about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-10 07:14:45 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-10 07:14:45 -0700
commitfbad3dd2056d215397b58c49f4f9a13199cbb260 (patch)
treec4364b1af719bdfed032242542df40497c8dc309
parentf554ce878b3bda9488e71015cc4c56046d0cef17 (diff)
downloadtext.love-fbad3dd2056d215397b58c49f4f9a13199cbb260.tar.gz
avoid some string concatenations
file:write can write multiple args one after another; no need to
concatenate them first.

I'm starting to pay attention to memory usage after the experience of
turning off the JIT.
-rw-r--r--file.lua12
1 files changed, 6 insertions, 6 deletions
diff --git a/file.lua b/file.lua
index 2374bb5..33c624c 100644
--- a/file.lua
+++ b/file.lua
@@ -34,7 +34,7 @@ function save_to_disk(lines, filename)
     if line.mode == 'drawing' then
       store_drawing(outfile, line)
     else
-      outfile:write(line.data..'\n')
+      outfile:write(line.data, '\n')
     end
   end
   outfile:close()
@@ -82,21 +82,21 @@ function store_drawing(outfile, drawing)
   outfile:write('```lines\n')
   for _,shape in ipairs(drawing.shapes) do
     if shape.mode == 'freehand' then
-      outfile:write(json.encode(shape)..'\n')
+      outfile:write(json.encode(shape), '\n')
     elseif shape.mode == 'line' or shape.mode == 'manhattan' then
       local line = json.encode({mode=shape.mode, p1=drawing.points[shape.p1], p2=drawing.points[shape.p2]})
-      outfile:write(line..'\n')
+      outfile:write(line, '\n')
     elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
       local obj = {mode=shape.mode, vertices={}}
       for _,p in ipairs(shape.vertices) do
         table.insert(obj.vertices, drawing.points[p])
       end
       local line = json.encode(obj)
-      outfile:write(line..'\n')
+      outfile:write(line, '\n')
     elseif shape.mode == 'circle' then
-      outfile:write(json.encode({mode=shape.mode, center=drawing.points[shape.center], radius=shape.radius})..'\n')
+      outfile:write(json.encode({mode=shape.mode, center=drawing.points[shape.center], radius=shape.radius}), '\n')
     elseif shape.mode == 'arc' then
-      outfile:write(json.encode({mode=shape.mode, center=drawing.points[shape.center], radius=shape.radius, start_angle=shape.start_angle, end_angle=shape.end_angle})..'\n')
+      outfile:write(json.encode({mode=shape.mode, center=drawing.points[shape.center], radius=shape.radius, start_angle=shape.start_angle, end_angle=shape.end_angle}), '\n')
     elseif shape.mode == 'deleted' then
       -- ignore
     else