Skip to content

Commit

Permalink
Use more efficient implementation of get_new_inst_path
Browse files Browse the repository at this point in the history
Co-authored-by: Kenneth Loeffler <[email protected]>
  • Loading branch information
Dekkonot and kennethloeffler authored Jul 31, 2024
1 parent 87e9300 commit 6b1a12e
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/syncback/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,17 @@ impl<'sync> SyncbackSnapshot<'sync> {
/// where you would look for the object in Roblox Studio.
#[inline]
pub fn get_new_inst_path(&self, referent: Ref) -> String {
let mut path = Vec::new();
let mut path_capacity = 0;

let mut inst = self.get_new_instance(referent);
while let Some(instance) = inst {
path.push(&instance.name);
path_capacity += instance.name.len() + 1;
inst = self.get_new_instance(instance.parent());
}
let mut str = String::with_capacity(path_capacity);
while let Some(segment) = path.pop() {
str.push_str(segment);
str.push('/')
}
str.pop();
let mut path = Vec::new();

str
}
let mut inst = self.get_new_instance(referent);
while let Some(instance) = inst {
path.push(instance.name.as_str());
inst = self.get_new_instance(instance.parent());
}

path.reverse();
path.join("/")
}

/// Returns an Instance from the old tree with the provided referent, if it
/// exists.
Expand Down

0 comments on commit 6b1a12e

Please sign in to comment.