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

Prevent cloning on every get_xxx() call #793

Merged
merged 1 commit into from
Mar 21, 2023
Merged

Conversation

mqudsi
Copy link
Contributor

@mqudsi mqudsi commented Feb 9, 2023

Return a Cow<str> instead of String. We never use the allocated result and just compare against it, so there's no need to re-allocate each time.

Copy link
Member

@thomcc thomcc left a comment

Choose a reason for hiding this comment

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

Not public API so seems fine. Any reason why this is just for get_host? There are a few nearby that seem harmless to do it for.

@mqudsi
Copy link
Contributor Author

mqudsi commented Feb 9, 2023

I only changed the one I was using. Happy to update the rest 👍.

@thomcc
Copy link
Member

thomcc commented Feb 9, 2023

I don't think it's super important (these strings are all very small). That said, you feel a desire to anyway, it seems good to be consistent to the ones which are not public API, and exist also as a local.

They're dereferencing `Arc<String>` variables, but need a fallback in case the
variable wasn't set. This implies there's a desire to avoid cloning them
everywhere.

Return a `Cow<str>` instead of `String`. We never use the allocated results and
just compare against them, so there's no need to re-allocate each time.
@mqudsi mqudsi changed the title Prevent cloning on every get_host() call Prevent cloning on every get_xxx() call Feb 10, 2023
@mqudsi
Copy link
Contributor Author

mqudsi commented Feb 10, 2023

I've changed the other functions. Same case as before with the results of these private functions never being stored.

@thomcc thomcc merged commit 3eb17ab into rust-lang:main Mar 21, 2023
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

Successfully merging this pull request may close these issues.

None yet

2 participants