C: Introduce string_equals utility function#1130
Merged
marcoroth merged 3 commits intomarcoroth:mainfrom Feb 7, 2026
Merged
Conversation
e17b79b to
55dac47
Compare
citizen428
commented
Feb 6, 2026
src/include/util/str_utils.h
Outdated
| #include <stdbool.h> | ||
| #include <string.h> | ||
|
|
||
| static inline bool string_eq(const char* a, const char* b) { |
Contributor
Author
There was a problem hiding this comment.
Note that this is a header-only definition, which is common for this type of static inline function to ensure every compilation unit has its copy of the function.
marcoroth
reviewed
Feb 6, 2026
marcoroth
reviewed
Feb 6, 2026
string_eq utility functionstring_eq utility function
8e633d3 to
d5b9dd6
Compare
Contributor
Author
|
@marcoroth Renamed everything as requested. |
string_eq utility functionstring_equals utility function
marcoroth
reviewed
Feb 7, 2026
Signed-off-by: Marco Roth <marco.roth@intergga.ch>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: this was built on top of #1129, which should be merged first. I didn't want to update the already removed
visitsubcommand.This PR introduces a string utility function called
string_equalsand updates usages ofstrcmpto use that instead.Rationale:
While perusing
main.c, I found the repetitivestrcmpcalls a bit of a nuisance. I originally considered adding the following macro:However, since we're targeting C99, we can also use a
static inlinefunction instead.File size considerations:
I built the binary on my machine with both the
strcmpandstring_equalsversions. As expected, with our production flags, this resulted in no increased binary size asclangsuccessfully inlines all the calls. For debug builds, there's an increase of 448 bytes, which I think is a reasonable tradeoff for the increased readability.strcmpstring_eqOpen question:
Are we actually using the production flags to build releases? The assigned variable is never used in the
Makefile.