optimize performance for fitTextToWidth

This commit is contained in:
frto027 committed 2022-01-19 21:18:53 +08:00
1 parent f7afbada19
commit e0407f6355
1 file changed
+5 -5
+5 -5
View File
@@ -723,7 +723,7 @@ end
function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars) function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
local formatedLines = {} local formatedLines = {}
local curLength = 0 local curLength = 0
local text = "" local text = {}
local cursor = 1 local cursor = 1
local word_begin_index = 1 local word_begin_index = 1
@@ -803,11 +803,11 @@ function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
local wordLength = EID:getStrWidth(strFiltered) local wordLength = EID:getStrWidth(strFiltered)
if curLength + wordLength <= textboxWidth or curLength < 12 then if curLength + wordLength <= textboxWidth or curLength < 12 then
text = text .. word table.insert(text, word)
curLength = curLength + wordLength curLength = curLength + wordLength
else else
table.insert(formatedLines, text) table.insert(formatedLines, table.concat(text))
text = word text = { word }
curLength = wordLength curLength = wordLength
end end
@@ -817,7 +817,7 @@ function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
cursor = cursor + 1 cursor = cursor + 1
end end
table.insert(formatedLines, text) table.insert(formatedLines, table.concat(text))
return formatedLines return formatedLines
end end