luautf8
luautf8 copied to clipboard
Efficient use of find/sub
Consider such example:
repeat
pos = utf8.find(str,"\\",pos+1)
until not pos or utf8.sub(str,1,pos) ~= utf8.sub(str2,1,pos)
I have some doubt about efficiency of this code.
-
find
in looppos
value have to be translated to byte offset, and this get even worse with every iteration as we move further from beginning. So question: is there some internal optimization for loop usage? -
sub
afterfind
It has to repeat exactly the same translation ofpos
, which already was done infind
. So question: how to rewrite above example in more efficient way?