Last active
November 6, 2018 04:21
-
-
Save whatisaphone/ef2f13269b8c6e9a44909c1578c0e8cb to your computer and use it in GitHub Desktop.
Rust builder pattern performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct X { | |
a: i32, | |
b: i32, | |
c: i32, | |
d: i32, | |
} | |
impl X { | |
pub fn set_a_mut(&mut self, a: i32) { | |
self.a = a; | |
} | |
pub fn set_a_move(mut self, a: i32) -> Self { | |
self.a = a; | |
self | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://rust.godbolt.org/ | |
// rustc 1.29.0 | |
// -C opt-level=3 -C lto=thin -C codegen-units=1 | |
example::X::set_a_mut: | |
mov dword ptr [rdi], esi | |
ret | |
example::X::set_a_move: | |
mov dword ptr [rsi], edx | |
mov eax, dword ptr [rsi] | |
mov dword ptr [rdi], eax | |
mov rax, qword ptr [rsi + 4] | |
mov qword ptr [rdi + 4], rax | |
mov eax, dword ptr [rsi + 12] | |
mov dword ptr [rdi + 12], eax | |
mov rax, rdi | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment