Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficient use of find/sub #25

johnd0e opened this issue Sep 4, 2019 · 0 comments


Copy link

commented Sep 4, 2019

Consider such example:

    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.

  1. find in loop
    pos 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?
  2. sub after find
    It has to repeat exactly the same translation of pos, which already was done in find.
    So question: how to rewrite above example in more efficient way?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.