Skip to content

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

Closed
@hanna-kruppe

Description

@hanna-kruppe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions