admin管理员组文章数量:1122846
In the below code I've created 2 Arc
's in two different ways. So, want to know whether compiler will optimize the first Arc
creation?
use std::sync::Arc;
#[derive(Debug)]
struct A {
id: u64,
a: i32,
b: f64,
c: String,
}
impl A {
fn new(id: u64) -> Self {
Self {
id,
a: 34,
b: 3.4,
c: "default".to_string(),
}
}
}
fn main() {
let a_obj = A::new(1);
// a_obj will be moved while creating arc1 which will result in copy operation.
// So, is this slow compared to the way arc2 is created?
// Or, compiler will optimize this operation?
let arc1 = Arc::new(a_obj);
let arc2 = Arc::new(A::new(2));
}
本文标签: rustCompiler optimization while creating an ArcStack Overflow
版权声明:本文标题:rust - Compiler optimization while creating an Arc - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283151a1926871.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论