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

Use strlen() 3 times instead of custom length check implementations in ustring #99817

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

Ivorforce
Copy link
Member

@Ivorforce Ivorforce commented Nov 29, 2024

strlen(char32_t *) unfortunately does not exist and has to be added. The implementation speed should be the same or slightly better, except for the char *p_str case where it may be slightly better now, because the compiler might not previously have realized that it can use the optimized strlen instead of rolling its own loop.

@Ivorforce Ivorforce requested a review from a team as a code owner November 29, 2024 01:08
@Chaosus Chaosus added this to the 4.4 milestone Nov 29, 2024
@AThousandShips AThousandShips modified the milestones: 4.4, 4.x Nov 29, 2024
@Ivorforce
Copy link
Member Author

Ivorforce commented Nov 29, 2024

Here is a demonstration of the difference in generated bytecode between the two approaches:

https://godbolt.org/z/Tjhs9hWr7 (-O2: https://godbolt.org/z/eGaEKj3oY)

(the function will likely be inlined since it's defined in the same file)

It's unlikely to make a noticeable difference; it's better to view the PR as a clean-up refactor, but it is slightly better.

Copy link
Member

@adamscott adamscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok! I would love a review from @KoBeWi or @Calinou too before merging.

@adamscott adamscott requested review from Calinou and KoBeWi November 30, 2024 20:10
@adamscott adamscott changed the title Use strlen 3 times instead of custom length check implementations in ustring Use strlen() 3 times instead of custom length check implementations in ustring Nov 30, 2024
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me.

@adamscott adamscott modified the milestones: 4.x, 4.4 Dec 1, 2024
@akien-mga akien-mga requested review from bruvzg and removed request for KoBeWi December 2, 2024 13:53
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not make any noticeable difference, code looks fine.

…rlen, adding an implementation for char32_t.
@Repiteo Repiteo merged commit 45734bd into godotengine:master Dec 5, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 5, 2024

Thanks!

@Ivorforce Ivorforce deleted the strlen-char32_t branch December 5, 2024 22:43
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.

8 participants