reduce use of rfind
[?]
Jan 13, 2023, 5:10 PM
NQM25OZVXXUTUBIIWE2QPHC22JMJB7YRIDKS2XTMQLJLCMLTM5SACDependencies
- [2]
6K5PFF6Xhelper: trimming whitespace from strings - [3]
DW6SNODMsource editing: highlight [[ ]] comments/strings - [4]
KKMFQDR4editing source code from within the app - [*]
BULPIBEGbeginnings of a module for the text editor - [*]
PLKNHYZ4extract a function - [*]
LXTTOB33extract a couple of files
Change contents
- edit in text.lua at line 1003
endfunction starts_with(s, prefix)if #s < #prefix thenreturn falseendfor i=1,#prefix doif s:sub(i,i) ~= prefix:sub(i,i) thenreturn falseendendreturn trueendfunction ends_with(s, suffix)if #s < #suffix thenreturn falseendfor i=0,#suffix-1 doif s:sub(#s-i,#s-i) ~= suffix:sub(#suffix-i,#suffix-i) thenreturn falseendendreturn true - edit in search.lua at line 119[8.51767][4.177926]
-- TODO: avoid the expensive reverse() operations-- Particularly if we only care about literal matches, we don't need all of string.find - replacement in colorize.lua at line 63
if edge.prefix and find(frag, edge.prefix, nil, --[[plain]] true) == 1 thenif edge.prefix and starts_with(frag, edge.prefix) then - replacement in colorize.lua at line 76
if edge.suffix and rfind(frag, edge.suffix, nil, --[[plain]] true) == #frag - #edge.suffix + 1 thenif edge.suffix and ends_with(frag, edge.suffix) then - edit in colorize.lua at line 81
endfunction trim(s)return s:gsub('^%s+', ''):gsub('%s+$', '')endfunction ltrim(s)return s:gsub('^%s+', '')endfunction rtrim(s)return s:gsub('%s+$', '')