guessLicense(): create space-changing meta-regex outside loop

This commit is contained in:
someguy126 2014-12-08 12:03:04 -08:00 committed by Thaddee Tyl
parent 3b84814c3a
commit c32a93b99d

View File

@ -2891,9 +2891,10 @@ function guessLicense(text) {
}
var licenseCodes = Object.keys(licensePhrases);
var licenseRegex;
var spaceMetaRegex = new RegExp(' ', 'g');
for(var i = 0; i < licenseCodes.length; i++) {
// Spaces can be any whitespace
licenseRegex = licensePhrases[licenseCodes[i]].replace(new RegExp(' ', 'g'), '\\s+');
licenseRegex = licensePhrases[licenseCodes[i]].replace(spaceMetaRegex, '\\s+');
if(text.match(new RegExp(licenseRegex, 'i'))) {
return licenseCodes[i];
}