1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-09-28 06:31:07 +10:00

Memopt on keymaps before I go for the grand glacier/everest memopt prize

This commit is contained in:
20kdc 2018-03-22 23:54:11 +00:00
parent 7b9f1a2776
commit dc0feff44d

View File

@ -119,7 +119,15 @@ keymaps = {
{45, "qjkxbmwvz"}, {45, "qjkxbmwvz"},
}, },
} }
local unknownKeymapContains = {} for k, v in pairs(keymaps) do
for k2, v2 in ipairs(v) do
for i = 1, unicode.len(v2[2]) do
v[unicode.sub(v2[2], i, i)] = i + v2[1] - 1
end
v2[k2] = nil
end
end
currentKeymap = "unknown" currentKeymap = "unknown"
-- Not really part of this package, but... -- Not really part of this package, but...
unicode.getKeymap = function () unicode.getKeymap = function ()
@ -129,20 +137,12 @@ end
-- Due to a fantastic oversight, unicode.byte or such doesn't exist in OCEmu, -- Due to a fantastic oversight, unicode.byte or such doesn't exist in OCEmu,
-- so things are managed via "Ch" internally. -- so things are managed via "Ch" internally.
unicode.getKCByCh = function (ch, km) unicode.getKCByCh = function (ch, km)
for _, v in ipairs(keymaps[km]) do return keymaps[km][ch]
local spanLen = unicode.len(v[2])
for i = 1, spanLen do
if unicode.sub(v[2], i, i) == ch then
return v[1] + i - 1
end
end
end
end end
unicode.getChByKC = function (kc, km) unicode.getChByKC = function (kc, km)
for _, v in ipairs(keymaps[km]) do for ach, akc in pairs(keymaps[km]) do
local spanLen = unicode.len(v[2]) if akc == kc then
if kc >= v[1] and kc < v[1] + spanLen then return ach
return unicode.sub(v[2], kc + 1 - v[1], kc + 1 - v[1])
end end
end end
end end
@ -152,9 +152,8 @@ local function keymapDetect(ka, kc)
-- simple algorithm, does the job -- simple algorithm, does the job
-- emergencyFunction("KD: " .. unicode.char(signal[3]) .. " " .. signal[4]) -- emergencyFunction("KD: " .. unicode.char(signal[3]) .. " " .. signal[4])
ka = unicode.char(ka) ka = unicode.char(ka)
if unknownKeymapContains[ka] ~= kc then if keymaps["unknown"][ka] ~= kc then
unknownKeymapContains[ka] = kc keymaps["unknown"][ka] = kc
table.insert(keymaps["unknown"], {kc, ka})
else else
return return
end end
@ -166,7 +165,7 @@ local function keymapDetect(ka, kc)
if k ~= "unknown" then if k ~= "unknown" then
local count = 0 local count = 0
local total = 0 local total = 0
for kCh, kc in pairs(unknownKeymapContains) do for kCh, kc in pairs(keymaps["unknown"]) do
if unicode.getKCByCh(kCh, k) == kc then if unicode.getKCByCh(kCh, k) == kc then
count = count + 1 count = count + 1
end end