operation: make Operation object cheaply clonable

We do clone Operation object in several places, and I'm going to add one more
.clone() in the templater. Since the underlying metadata has many fields, I
think it's better to wrap it with Arc just like a Commit object.
This commit is contained in:
Yuya Nishihara 2024-02-22 17:04:07 +09:00
parent 62f0cb8c3f
commit 073310547c

View file

@ -27,7 +27,7 @@ use crate::view::View;
pub struct Operation {
op_store: Arc<dyn OpStore>,
id: OperationId,
data: op_store::Operation,
data: Arc<op_store::Operation>, // allow cheap clone
}
impl Debug for Operation {
@ -63,8 +63,16 @@ impl Hash for Operation {
}
impl Operation {
pub fn new(op_store: Arc<dyn OpStore>, id: OperationId, data: op_store::Operation) -> Self {
Operation { op_store, id, data }
pub fn new(
op_store: Arc<dyn OpStore>,
id: OperationId,
data: impl Into<Arc<op_store::Operation>>,
) -> Self {
Operation {
op_store,
id,
data: data.into(),
}
}
pub fn op_store(&self) -> Arc<dyn OpStore> {