Skip to content

Commit

Permalink
fix: remove redundant node clone for derive (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Millione authored May 9, 2024
1 parent b3aa605 commit 50ed98b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "metainfo"
version = "0.7.9"
version = "0.7.10"
authors = ["Volo Team <[email protected]>"]
edition = "2021"
description = "Transmissing metainfo across components."
Expand Down
26 changes: 24 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl MetaInfo {
///
/// This is the recommended way.
#[inline]
pub fn derive(self) -> (MetaInfo, MetaInfo) {
pub fn derive(mut self) -> (MetaInfo, MetaInfo) {
if self.tmap.is_none() && self.smap.is_none() && self.faststr_tmap.is_none() {
// we can use the same parent as self to make the tree small
let new = MetaInfo {
Expand All @@ -121,8 +121,30 @@ impl MetaInfo {
};
(self, new)
} else {
let forward_node = self.forward_node.take();
let backward_node = self.backward_node.take();
let mi = Arc::new(self);
(Self::from(mi.clone()), Self::from(mi))
(
MetaInfo::from_node(mi.clone(), forward_node.clone(), backward_node.clone()),
MetaInfo::from_node(mi, forward_node, backward_node),
)
}
}

/// Creates an `MetaInfo` with the parent and node given.
fn from_node(
parent: Arc<MetaInfo>,
forward_node: Option<kv::Node>,
backward_node: Option<kv::Node>,
) -> MetaInfo {
MetaInfo {
parent: Some(parent),
tmap: None,
smap: None,
faststr_tmap: None,

forward_node,
backward_node,
}
}

Expand Down

0 comments on commit 50ed98b

Please sign in to comment.