Is there any smarter way to do type conversion on Vec rather than using for loop?
many thanks anyway
Using into_iter + map + collect gets optimized well, too:
pub fn convert(x: Vec<i64>) -> Vec<u64> {
x.into_iter().map(|n| n as _).collect()
}
Rust Playground (click “ASM” as a build option)
playground::convert:
movq %rdi, %rax
movq (%rsi), %rcx
movups 8(%rsi), %xmm0
movq %rcx, (%rdi)
movups %xmm0, 8(%rdi)
retq
5 Likes
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.