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

Return Cow<str> from to_case method. #22

Closed
chernoivanenkoofficial opened this issue Jan 6, 2025 · 1 comment
Closed

Return Cow<str> from to_case method. #22

chernoivanenkoofficial opened this issue Jan 6, 2025 · 1 comment

Comments

@chernoivanenkoofficial
Copy link

If a referenced str is already in requested case, is there any reason why it shouldn't be returned in borrowed view?

@rutrum
Copy link
Owner

rutrum commented Jan 7, 2025

The current algorithm for case transformation doesn't perform any overhead to check any properties of the input string. Even if the operations don't make any changes, there are still some borrowing and cloning that happens are part of the conversion. There's improvements to be made in this regard, but in general I don't think the overhead of checking if it's already a case is worth the savings of not copying the string. I suspect most use cases of case conversion you explicitly know that a string isn't the right case, which is why you convert it. Is there a use case you are thinking of where this performance advantage would be substantial?

@rutrum rutrum closed this as completed Mar 5, 2025
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

No branches or pull requests

2 participants