Skip to content

Conversation

@EmilianC
Copy link

@EmilianC EmilianC commented Jul 21, 2024

The first strlen() call required that the searchName is iterated entirely, even if the following strncmp() would be able to early-out when the first characters don't match.

The pre-calculated length is only used to constrain the string comparison, but strcmp() will handle the ends of both strings just fine, and early-out as soon as possible.

The second call to strlen() was to ensure that searchName didn't just match a prefix of a longer currentName. strcmp() also accounts for this, but will early-out if the string is a single character longer, without having to walk the entire currentName.

@EmilianC EmilianC closed this Jul 21, 2024
@EmilianC EmilianC reopened this Jul 21, 2024
@EmilianC EmilianC force-pushed the json-load-string-comparison-optimization branch from 122179a to 7d1d4c5 Compare July 21, 2024 04:54
@EmilianC
Copy link
Author

Pardon, silly extra , len argument snuck in last minute when making the PR :) Fixed in 7d1d4c5

@AzothAmmo AzothAmmo added this to the v1.3.3 milestone Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants