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

str::to_owned doesn't generate exactly the same code as String::from #32163

Closed
hanna-kruppe opened this issue Mar 9, 2016 · 0 comments
Closed
Labels
A-codegen Area: Code generation

Comments

@hanna-kruppe
Copy link
Contributor

to_owned is not marked #[inline] while String::from is. Check the assembly, one is inlined and the other isn't. It probably doesn't matter and in fact I can't measure any performance difference with short strings (and long ones are probably dominated by the memcpy anyway). Maybe we should just stop inlining from to make binaries a tiny bit smaller. Either way, it's unfortunate that these two conversion methods, which are often described as being exactly equivalent, aren't.

@steveklabnik steveklabnik added A-codegen Area: Code generation A-libs labels Mar 11, 2016
bors added a commit that referenced this issue Mar 13, 2016
Call str::to_owned in String::from and uninline it

Call str::to_owned in String::from and uninline it

These methods were already effectively equal, but now one calls
the other, and neither is marked inline.
String::from does not need to be inlined, it can be without it just like
str::to_owned and String::clone are.

Fixes #32163
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

No branches or pull requests

2 participants