Closed
Description
Since 1.52.0 Rust copy byte from static memory for creating String by Default::default()
. But when uses "".to_string()
it doesn't happen.
Additional instruction appears when use Default::default()
(godbolt)
pub fn string_default() -> String {
Default::default()
}
pub fn string_to_string() -> String {
"".to_string()
}
example::string_default:
mov rax, rdi
mov rcx, qword ptr [rip + .L__unnamed_1]
xorps xmm0, xmm0
movups xmmword ptr [rdi + 8], xmm0
mov qword ptr [rdi], rcx
ret
example::string_to_string:
mov rax, rdi
xorps xmm0, xmm0
movups xmmword ptr [rdi + 8], xmm0
mov qword ptr [rdi], 1
ret
.L__unnamed_1:
.asciz "\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
Metadata
Metadata
Assignees
Labels
No labels