Don't copy in `From<String> for InternedString`.
If we have an owned String already, then don't clone it just to internalise it.
What does this PR try to resolve?
Before, InternedString::from(String::new("blahblah")) would take ownership of the String but then make and leak a copy (str.to_string().leak()) for use in the interned_storage(). This change just avoids that copy, which I think was the intention behind the interface and the interning mechanism.
How should we test and review this PR?
Several existing tests hit this implementation, so I'd expect cargo test to suffice for functional correctness. The implementation of InternedString::new() (a few lines down) is useful as a reference.
Additional information
Whilst it looks like an optimisation, I've no particular performance objective here. This was just something I noticed whilst looking around the code.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @epage (or someone else) some time within the next two weeks.
Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:
-
@rustbot author: the review is finished, PR author should check the comments and take action accordingly -
@rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue