improve: 改进 v_filter 的性能 (#147)

This commit is contained in:
t123yh 2023-04-07 21:05:58 +08:00 committed by GitHub
parent d859ee255e
commit 58e5a08ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -237,6 +237,8 @@ end
-- 把候选项应改为「ā á ǎ à …… van vain」让单个字符的排在前面
function v_filter(input, env)
local code = env.engine.context.input -- 当前编码
-- 仅当当前输入以 v 开头,并且编码长度为 2才进行处理
if (string.len(code) == 2 and string.find(code, "v") == 1) then
local l = {}
for cand in input:iter() do
-- 特殊情况处理
@ -244,15 +246,15 @@ function v_filter(input, env)
yield(cand)
end
-- 特殊情况处理
local arr = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
local arr = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }
for _, v in ipairs(arr) do
if (v == cand.text and string.len(code) == 2 and string.find(code, "v") == 1) then
if (v == cand.text) then
yield(cand)
break
end
end
-- 以 v 开头、2 个长度的编码、候选项为单个字符的,提到前面来。
if (string.len(code) == 2 and string.find(code, "v") == 1 and utf8.len(cand.text) == 1) then
-- 候选项为单个字符的,提到前面来。
if (utf8.len(cand.text) == 1) then
yield(cand)
else
table.insert(l, cand)
@ -261,6 +263,11 @@ function v_filter(input, env)
for _, cand in ipairs(l) do
yield(cand)
end
else
for cand in input:iter() do
yield(cand)
end
end
end
-------------------------------------------------------------
-- iRime 九宫格专用,将输入框的数字转为对应的拼音或英文