milo perf + cleanup

This commit is contained in:
kepler155c@gmail.com
2019-01-26 00:28:46 -05:00
parent 779d58cd7e
commit bae28521db
7 changed files with 69 additions and 61 deletions

View File

@@ -3,20 +3,17 @@
--
-- not very fuzzy anymore
local SCORE_WEIGHT = 1000
local LEADING_LETTER_PENALTY = -3
local SCORE_WEIGHT = 1000
local LEADING_LETTER_PENALTY = -3
local LEADING_LETTER_PENALTY_MAX = -9
local _find = string.find
local _max = math.max
return function(str_lower, ptrn_lower)
local score = 0
local start = _find(str_lower, ptrn_lower, 1, true)
return function(str, pattern)
local start = _find(str, pattern, 1, true)
if start then
-- All letters before the current one are considered leading, so add them to our penalty
score = SCORE_WEIGHT + math.max(LEADING_LETTER_PENALTY * (start - 1), LEADING_LETTER_PENALTY_MAX)
return SCORE_WEIGHT + _max(LEADING_LETTER_PENALTY * (start - 1), LEADING_LETTER_PENALTY_MAX)
end
return score
end