[Github-comments] [geany/geany] Use strchr instead of strstr (PR #2962)

Andy Alt notifications at xxxxx
Thu Nov 25 07:31:46 UTC 2021


> The problem with `strlen("Entering directory '")` is `strlen` runs in linear time... basically equivalent to just rescanning (that portion of) the string. (Don't know whether compilers can optimize it to a constant.)
> 

It looks like @elextr nixed the idea of moving the pointer ahead for this case, but for future reference, I think you could use `sizeof "Entering directory"` instead of strlen. Because it's a constant, sizeof can be used, then the number will be known at compile-time and won't need to be computed at run-time. (Sometimes it will be important to be mindful that using the `sizeof` operator will give the result of the string length + 1 for the NULL terminator.



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/2962#issuecomment-978907669
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20211124/f7b58863/attachment.htm>


More information about the Github-comments mailing list