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

Optimize String.capitalize by running the capitalization algorithm inplace. #100486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ivorforce
Copy link
Contributor

@Ivorforce Ivorforce commented Dec 16, 2024

This optimizes the capitalize-internal portion of capitalize, avoiding repeated allocations.
I think the function is now optimal; the rest is likely inefficiency from the _camelcase_to_underscore call, the to_lower call (optimized by #99971), and the replace call (optimized by #92475)

The overall speed of the capitalize() benchmark is improved by 25%.

newplot

@Ivorforce Ivorforce requested a review from a team as a code owner December 16, 2024 19:35
@Chaosus Chaosus added this to the 4.x milestone Dec 17, 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