mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 21:07:43 +00:00
perf: replace returned vec with iterator
This commit is contained in:
parent
402b174842
commit
521615b1a0
1 changed files with 13 additions and 14 deletions
|
@ -318,24 +318,23 @@ impl<
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_range(&self, start: Index, end: Index) -> Vec<&Value> {
|
||||
let mut ans = Vec::new();
|
||||
for value in self.tree.iter_range(start, Some(end)) {
|
||||
ans.push(&value.as_tree_ref().value)
|
||||
}
|
||||
ans
|
||||
pub fn get_range(&self, start: Index, end: Index) -> impl Iterator<Item = &Value> {
|
||||
self.tree
|
||||
.iter_range(start, Some(end))
|
||||
.map(|x| &x.as_tree_ref().value)
|
||||
}
|
||||
|
||||
/// TODO: need double check this method
|
||||
#[inline]
|
||||
pub fn get_range_with_index(&self, start: Index, end: Index) -> Vec<(Index, &Value)> {
|
||||
let mut ans = Vec::new();
|
||||
for value in self.tree.iter_range(start, Some(end)) {
|
||||
let value = value.as_tree_ref();
|
||||
ans.push((value.index, &value.value));
|
||||
}
|
||||
|
||||
ans
|
||||
pub fn get_range_with_index(
|
||||
&self,
|
||||
start: Index,
|
||||
end: Index,
|
||||
) -> impl Iterator<Item = (Index, &Value)> {
|
||||
self.tree.iter_range(start, Some(end)).map(|x| {
|
||||
let x = x.as_tree_ref();
|
||||
(x.index, &x.value)
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in a new issue