TextBoxWidget: optimize memory usage (#3904)

By reducing the number of data structures, and avoiding nested tables,
which seemed to impose a lot of work on the garbage collector.
This commit is contained in:
poire-z
2018-04-21 22:16:14 +02:00
committed by Frans de Jonge
parent 941df475b6
commit d601eabc4a
2 changed files with 83 additions and 69 deletions

View File

@@ -273,14 +273,14 @@ function MenuItem:init()
if item_name.vertical_string_list[lines + 1] then
offset = item_name.vertical_string_list[lines + 1].offset - 2
else -- shouldn't happen, but just in case
offset = #item_name.char_width_list
offset = #item_name.charlist
end
local ellipsis_size = RenderText:sizeUtf8Text(0, self.content_width,
Font:getFace(self.font, self.font_size), "", true, self.bold).x
local removed_char_width= 0
while removed_char_width < ellipsis_size do
-- the width of each char has already been calculated by TextBoxWidget
removed_char_width = removed_char_width + item_name.char_width_list[offset].width
removed_char_width = removed_char_width + item_name:geCharWidth(offset)
offset = offset - 1
end
self.text = table.concat(item_name.charlist, '', 1, offset) .. ""