milo perf + cleanup
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -149,9 +149,7 @@ end
|
||||
|
||||
-- queue up an action that relies on the crafting grid
|
||||
function Milo:queueRequest(request, callback)
|
||||
if Util.empty(self.context.queue) then
|
||||
os.queueEvent('milo_queue')
|
||||
end
|
||||
os.queueEvent('milo_queue')
|
||||
table.insert(self.context.queue, {
|
||||
request = request,
|
||||
callback = callback
|
||||
|
||||
@@ -122,6 +122,12 @@ function Storage:initStorage()
|
||||
v.adapter = device[k]
|
||||
v.adapter.online = true
|
||||
end
|
||||
|
||||
if v.adapter then
|
||||
-- force a new getTransferLocations() as the list may have changed
|
||||
v.adapter.transferLocations = nil
|
||||
end
|
||||
|
||||
if v.mtype == 'storage' then
|
||||
online = online and not not (v.adapter and v.adapter.online)
|
||||
end
|
||||
@@ -334,7 +340,13 @@ function Storage:_sn(name)
|
||||
end
|
||||
|
||||
local function isValidTransfer(adapter, target)
|
||||
for _,v in pairs(adapter.getTransferLocations()) do
|
||||
-- lazily cache transfer locations
|
||||
local transferLocations = adapter.transferLocations
|
||||
if not transferLocations then
|
||||
transferLocations = adapter.getTransferLocations()
|
||||
adapter.transferLocations = transferLocations
|
||||
end
|
||||
for _,v in pairs(transferLocations) do
|
||||
if v == target then
|
||||
return true
|
||||
end
|
||||
@@ -500,7 +512,6 @@ function Storage:import(source, slot, count, item)
|
||||
total = total + self:trash(source, slot, count)
|
||||
return total
|
||||
end
|
||||
--return total
|
||||
end
|
||||
if count <= 0 then
|
||||
return total
|
||||
|
||||
Reference in New Issue
Block a user