remove unnecessary csp makePredicate - fixes #1267
This commit is contained in:
parent
9e21074e88
commit
24b13c5e49
@ -9,41 +9,9 @@
|
|||||||
|
|
||||||
function makePredicate(words) {
|
function makePredicate(words) {
|
||||||
words = words.split(" ")
|
words = words.split(" ")
|
||||||
let f = "", cats = []
|
return function(str) {
|
||||||
out: for (let i = 0; i < words.length; ++i) {
|
return words.indexOf(str) >= 0
|
||||||
for (let j = 0; j < cats.length; ++j)
|
|
||||||
if (cats[j][0].length == words[i].length) {
|
|
||||||
cats[j].push(words[i])
|
|
||||||
continue out
|
|
||||||
}
|
}
|
||||||
cats.push([words[i]])
|
|
||||||
}
|
|
||||||
function compareTo(arr) {
|
|
||||||
if (arr.length == 1) return f += "return str === " + JSON.stringify(arr[0]) + ";"
|
|
||||||
f += "switch(str){"
|
|
||||||
for (let i = 0; i < arr.length; ++i) f += "case " + JSON.stringify(arr[i]) + ":"
|
|
||||||
f += "return true}return false;"
|
|
||||||
}
|
|
||||||
|
|
||||||
// When there are more than three length categories, an outer
|
|
||||||
// switch first dispatches on the lengths, to save on comparisons.
|
|
||||||
|
|
||||||
if (cats.length > 3) {
|
|
||||||
cats.sort((a, b) => b.length - a.length)
|
|
||||||
f += "switch(str.length){"
|
|
||||||
for (let i = 0; i < cats.length; ++i) {
|
|
||||||
let cat = cats[i]
|
|
||||||
f += "case " + cat[0].length + ":"
|
|
||||||
compareTo(cat)
|
|
||||||
}
|
|
||||||
f += "}"
|
|
||||||
|
|
||||||
// Otherwise, simply generate a flat `switch` statement.
|
|
||||||
|
|
||||||
} else {
|
|
||||||
compareTo(words)
|
|
||||||
}
|
|
||||||
return new Function("str", f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reserved word lists for various dialects of the language
|
// Reserved word lists for various dialects of the language
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user