<commit_before>/*!
 * micromatch <https://github.com/jonschlinkert/micromatch>
 *
 * Copyright (c) 2014 <NAME>, contributors.
 * Licensed under the MIT license.
 */

'use strict';

var unixify = require('unixify');
var union = require('arr-union');
var diff = require('arr-diff');
var braces = require('braces');

function makeRe(glob, options) {
  var opts = options || {};
  var flags = opts.flags || '';
  var i = 0;

  // only recompile regex if options change
  optsCache = optsCache || opts;
  if (!equal(optsCache, opts)) {
    regex = null;
    cache = glob;
  }

  // only recompile regex if glob changes
  cache = cache || glob;
  if (cache !== glob) {
    glob = unixify(glob);
    regex = null;
    cache = glob;
  }

  // if `true`, then we can just return
  // the regex that was previously cached
  if (regex instanceof RegExp) {
    return regex;
  }

  // expand `{1..5}` braces
  if (/\{/.test(glob)) {
    glob = expand(glob);
  }

  var len = tokens.length;
  while (i < len) {
    var group = tokens[i++];
    var re = group[1].re;
    var to = group[1].to;

    // apply special cases from options
    for (var key in opts) {
      if (group[1].hasOwnProperty(key)) {
        to += group[1][key];
      }
    }
    glob = glob.replace(re, to);
  }

  if (opts.nocase) flags += 'i';

  // cache the regex
  regex = globRegex(glob, flags);
  // return the result
  return regex;
}

/**
 * Pass an array of files and a glob pattern as a string.
 * This function is called by the main `micromatch` function
 * If you only need to pass a single pattern you might get
 * minor speed improvements using this function.
 *
 * @param  {Array} `files`
 * @param  {Array} `pattern`
 * @param  {Object} `options`
 * @return {Array}
 */

function match(files, pattern, options) {
  if (typeof files !== 'string' && !Array.isArray(files)) {
    throw new Error('micromatch.match() expects a string or array.');
  }

  files = arrayify(files);
  var len = files.length;
  var res = [];
  var i = 0;

  while (i < len) {
    var fp = unixify(files[i++]);
    if (makeRe(pattern, options).test(fp)) {
      res.push(fp);
    }
  }
  return res;
}<commit_msg>move regex out of loop<commit_after>/*!
 * micromatch <https://github.com/jonschlinkert/micromatch>
 *
 * Copyright (c) 2014 <NAME>, contributors.
 * Licensed under the MIT license.
 */

'use strict';

var unixify = require('unixify');
var union = require('arr-union');
var diff = require('arr-diff');
var braces = require('braces');

function makeRe(glob, options) {
  var opts = options || {};
  var flags = opts.flags || '';
  var i = 0;

  // only recompile regex if options change
  optsCache = optsCache || opts;
  if (!equal(optsCache, opts)) {
    regex = null;
    cache = glob;
  }

  // only recompile regex if glob changes
  cache = cache || glob;
  if (cache !== glob) {
    glob = unixify(glob);
    regex = null;
    cache = glob;
  }

  // if `true`, then we can just return
  // the regex that was previously cached
  if (regex instanceof RegExp) {
    return regex;
  }

  // expand `{1..5}` braces
  if (/\{/.test(glob)) {
    glob = expand(glob);
  }

  var len = tokens.length;
  while (i < len) {
    var group = tokens[i++];
    var re = group[1].re;
    var to = group[1].to;

    // apply special cases from options
    for (var key in opts) {
      if (group[1].hasOwnProperty(key)) {
        to += group[1][key];
      }
    }
    glob = glob.replace(re, to);
  }

  if (opts.nocase) flags += 'i';

  // cache the regex
  regex = globRegex(glob, flags);
  // return the result
  return regex;
}

/**
 * Pass an array of files and a glob pattern as a string.
 * This function is called by the main `micromatch` function
 * If you only need to pass a single pattern you might get
 * minor speed improvements using this function.
 *
 * @param  {Array} `files`
 * @param  {Array} `pattern`
 * @param  {Object} `options`
 * @return {Array}
 */

function match(files, pattern, options) {
  if (typeof files !== 'string' && !Array.isArray(files)) {
    throw new Error('micromatch.match() expects a string or array.');
  }

  files = arrayify(files);
  var regex = makeRe(pattern, options);
  var len = files.length;
  var res = [];
  var i = 0;

  while (i < len) {
    var fp = unixify(files[i++]);
    if (regex.test(fp)) {
      res.push(fp);
    }
  }
  return res;
}
{'fraction_non_alphanumeric': 0.1506660542030317, 'fraction_numerical': 0.005512172714745062, 'mean_word_length': 2.764044943820225, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '5020120', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1438, 'n_words': 477}