about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-09 07:24:40 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-09 07:24:40 -0700
commite77157d316cde82faaa52dabfa66cd3253cb8abf (patch)
tree86667206dfda20dcee973afcc81e2adde8563c8d
parentac4879bb850e2ce3ed9830cc3ff4286f36c0bad4 (diff)
downloadtext.love-e77157d316cde82faaa52dabfa66cd3253cb8abf.tar.gz
speeding up copy, attempt 1
Problem: repeatedly copying (relatively large) sections of text quickly
makes the app sluggish until it has to be killed. (Thanks John Blommers
for the report.)

When I instrument with prints, the sluggishness seems to happen in
random draw() calls many times after I perform the copy.

I don't know for sure, but I'm initially checking if the cause is
garbage generated by repeated string concatenation.

This attempt doesn't seem to make any difference.
-rw-r--r--select.lua8
1 files changed, 4 insertions, 4 deletions
diff --git a/select.lua b/select.lua
index 3d8999e..57791d5 100644
--- a/select.lua
+++ b/select.lua
@@ -163,14 +163,14 @@ function Text.selection()
     return Lines[minl].data:sub(min_offset, max_offset-1)
   end
   assert(minl < maxl)
-  local result = Lines[minl].data:sub(min_offset)..'\n'
+  local result = {Lines[minl].data:sub(min_offset)}
   for i=minl+1,maxl-1 do
     if Lines[i].mode == 'text' then
-      result = result..Lines[i].data..'\n'
+      table.insert(result, Lines[i].data)
     end
   end
-  result = result..Lines[maxl].data:sub(1, max_offset-1)
-  return result
+  table.insert(result, Lines[maxl].data:sub(1, max_offset-1))
+  return table.concat(result, '\n')
 end
 
 function Text.cut_selection()