Skip to content

Conversation

@thomaskroi1996
Copy link
Contributor

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

  • Tests added and pass
  • Adequate documentation added
  • (optional) Added Screenshots or videos

@thomaskroi1996 thomaskroi1996 requested a review from a team as a code owner December 17, 2025 15:10
Saviq
Saviq previously requested changes Dec 17, 2025
Copy link
Contributor

@Saviq Saviq left a 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 :)

@thomaskroi1996
Copy link
Contributor Author

ah, ups, that was my VSCode autosave, i am sorry for that, will fix it!

Copy link
Contributor

@Saviq Saviq left a 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.

Copy link
Contributor

@AlanGriffiths AlanGriffiths left a 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

Copy link
Contributor

@AlanGriffiths AlanGriffiths left a 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.

@thomaskroi1996 thomaskroi1996 changed the title replace strlen() with constexpr_strl() replace strlen() with strlen_c() Dec 20, 2025
thomaskroi1996 and others added 3 commits December 20, 2025 13:38
Co-authored-by: Alan Griffiths <alan@octopull.co.uk>
Co-authored-by: Alan Griffiths <alan@octopull.co.uk>
Copy link
Contributor

@AlanGriffiths AlanGriffiths left a 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

Copy link
Contributor

@AlanGriffiths AlanGriffiths left a 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

Copy link
Contributor

@AlanGriffiths AlanGriffiths left a 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

@AlanGriffiths AlanGriffiths added this pull request to the merge queue Jan 5, 2026
Merged via the queue into canonical:main with commit 7345d0a Jan 5, 2026
51 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't use strlen with string literals

4 participants