diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-11-18 11:30:57 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-11-18 11:32:01 -0800 |
commit | 007b965b11b681550ee2e2244a2f53e64e88697d (patch) | |
tree | e3bff0e0d71e896ea1d954ae7715f672b247bf0e /source_select.lua | |
parent | 5cce5115507800eeca7ba9c271e07c23473228f4 (diff) | |
download | lines.love-007b965b11b681550ee2e2244a2f53e64e88697d.tar.gz |
audit all asserts
Each one should provide a message that will show up within LÖVE. Stop relying on nearby prints to the terminal. I also found some unnecessary ones. There is some potential here for performance regressions: the format() calls will trigger whether or not the assertion fails, and cause allocations. So far Lua's GC seems good enough to manage the load even with Moby Dick, even in some situations that caused issues in the past like undo.
Diffstat (limited to 'source_select.lua')
-rw-r--r-- | source_select.lua | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/source_select.lua b/source_select.lua index 9b2a278..9ede1da 100644 --- a/source_select.lua +++ b/source_select.lua @@ -33,13 +33,13 @@ function Text.clip_selection(State, line_index, apos, bpos) -- fully contained return apos,bpos elseif a_ge then - assert(maxl == line_index) + assert(maxl == line_index, ('maxl %d not equal to line_index %d'):format(maxl, line_index)) return apos,maxp elseif b_lt then - assert(minl == line_index) + assert(minl == line_index, ('minl %d not equal to line_index %d'):format(minl, line_index)) return minp,bpos else - assert(minl == maxl and minl == line_index) + assert(minl == maxl and minl == line_index, ('minl %d, maxl %d and line_index %d are not all equal'):format(minl, maxl, line_index)) return minp,maxp end end @@ -127,7 +127,7 @@ function Text.delete_selection_without_undo(State) State.lines[minl].data = State.lines[minl].data:sub(1, min_offset-1)..State.lines[minl].data:sub(max_offset) return end - assert(minl < maxl) + assert(minl < maxl, ('minl %d not < maxl %d'):format(minl, maxl)) local rhs = State.lines[maxl].data:sub(max_offset) for i=maxl,minl+1,-1 do table.remove(State.lines, i) @@ -154,7 +154,7 @@ function Text.selection(State) if minl == maxl then return State.lines[minl].data:sub(min_offset, max_offset-1) end - assert(minl < maxl) + assert(minl < maxl, ('minl %d not < maxl %d'):format(minl, maxl)) local result = {State.lines[minl].data:sub(min_offset)} for i=minl+1,maxl-1 do if State.lines[i].mode == 'text' then |