mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-03 18:24:19 +00:00
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:
parent
62f0cb8c3f
commit
073310547c
1 changed files with 11 additions and 3 deletions
|
@ -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> {
|
||||
|
|
Loading…
Reference in a new issue