-
Notifications
You must be signed in to change notification settings - Fork 120
replace strlen() with strlen_c() #4576
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
Conversation
Saviq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomaskroi1996 you commited a lot of changes that shouldn't be here (mostly formatting, and the removal of options.md.include.
Please only check in changes relevant to the problem you're working on.
I recommend git -vp, never do git add -a :)
|
ah, ups, that was my VSCode autosave, i am sorry for that, will fix it! |
4386e5b to
ef3cb27
Compare
Saviq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename the file to something like constexpr_utils.h, so more can be introduced.
Co-authored-by: Michał Sawicz <michal@sawicz.net>
AlanGriffiths
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. There are a few practice we follow on the project that will help with using this code, hope they are not too burdensome
AlanGriffiths
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've been a bit overzealous in using strlen_c - it only useful for string literals.
Also a couple of clarifications.
And the title of the PR also needs updating.
Co-authored-by: Alan Griffiths <alan@octopull.co.uk>
Co-authored-by: Alan Griffiths <alan@octopull.co.uk>
AlanGriffiths
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should prefer the standard library function (which developers should be familiar with) unless there is a reason to use the constexpr version
AlanGriffiths
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s a couple of files with no meaningful changes. Otherwise looking good
AlanGriffiths
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thank you
Closes #4551
Hello, as discussed with @Saviq and @tarek-y-ismail, this is my attempt at replacing the strlen() calls throughout the codebase with a constexpr function!
I added the constexpr_strlen.h file in include/common/mir and made the function a inline, since it just returns the size of a string_view. This should work with string literals, and I didn't have any failed tests after replacing all the calls!
The only file where I didn't replace them was xcursor.c, since there i couldn't include <string_view>, as xcursor is a c file.
Let me know any suggestions, thanks!
Checklist