<commit_before>'use babel'

import slick from 'atom-slick'

const EscapeCharacterRegex = /[-!"#$%&'*+,/:;=?@|^~()<>{}[\]]/g

const cachedMatchesBySelector = new WeakMap()

const getCachedMatch = (selector, scopeChain) => {
  const cachedMatchesByScopeChain = cachedMatchesBySelector.get(selector)
  if (cachedMatchesByScopeChain) {
    return cachedMatchesByScopeChain[scopeChain]
  }
}

const setCachedMatch = (selector, scopeChain, match) => {
  let cachedMatchesByScopeChain = cachedMatchesBySelector.get(selector)
  if (!cachedMatchesByScopeChain) {
    cachedMatchesByScopeChain = {}
    cachedMatchesBySelector.set(selector, cachedMatchesByScopeChain)
  }
  cachedMatchesByScopeChain[scopeChain] = match
  cachedMatchesByScopeChain[scopeChain]
}

const parseScopeChain = (scopeChain) => {
  scopeChain = scopeChain.replace(EscapeCharacterRegex, (match) => {
    return '\\' + match[0]
  })

  const parsed = slick.parse(scopeChain)[0]<commit_msg>make selector match cache a plain object for speed<commit_after>'use babel'

import slick from 'atom-slick'

const EscapeCharacterRegex = /[-!"#$%&'*+,/:;=?@|^~()<>{}[\]]/g

const cachedMatchesBySelector = {}

const getCachedMatch = (selector, scopeChain) => {
  const cachedMatchesByScopeChain = cachedMatchesBySelector[selector]
  if (cachedMatchesByScopeChain) {
    return cachedMatchesByScopeChain[scopeChain]
  }
}

const setCachedMatch = (selector, scopeChain, match) => {
  let cachedMatchesByScopeChain = cachedMatchesBySelector[selector]
  if (!cachedMatchesByScopeChain) {
    cachedMatchesByScopeChain = {}
    cachedMatchesBySelector[selector] = cachedMatchesByScopeChain
  }
  cachedMatchesByScopeChain[scopeChain] = match
  cachedMatchesByScopeChain[scopeChain]
}

const parseScopeChain = (scopeChain) => {
  scopeChain = scopeChain.replace(EscapeCharacterRegex, (match) => {
    return '\\' + match[0]
  })

  const parsed = slick.parse(scopeChain)[0]
{'fraction_non_alphanumeric': 0.1266284523189161, 'fraction_numerical': 0.0020844189682126106, 'mean_word_length': 5.857142857142857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2930676', 'n_tokens_mistral': 618, 'n_tokens_neox': 610, 'n_words': 107}