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

libc/string: simplify strrchr #6229

Merged
merged 1 commit into from May 10, 2022
Merged

Conversation

juniskane
Copy link
Contributor

Summary

Do not call strlen() inside strrchr(). Old implementation iterated over string twice, if searched for position was at the beginning. This commit changes strrchr() to scan string only once, regardless of input.

At least my compiler with -O2 was not smart enough to get rid of strlen() call.

strrchr(s, 0) still works correctly with new implementation.

Impact

Minor optimization / code simplification

Testing

libs/libc/string/lib_strrchr.c Outdated Show resolved Hide resolved
libs/libc/string/lib_strrchr.c Outdated Show resolved Hide resolved
Do not call strlen() here. Old implementation iterated
over string twice, if searched for position was at the
beginning. This commit changes strrchr() to scan string
only once, regardless of input.

Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
@xiaoxiang781216 xiaoxiang781216 merged commit a17bfec into apache:master May 10, 2022
@jerpelea jerpelea added this to To-Add in Release Notes - 11.0.0 Aug 30, 2022
@jerpelea jerpelea moved this from To-Add to Added in Release Notes - 11.0.0 Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants