mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-06 12:25:03 +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]
|
#[inline]
|
||||||
pub fn get_range(&self, start: Index, end: Index) -> Vec<&Value> {
|
pub fn get_range(&self, start: Index, end: Index) -> impl Iterator<Item = &Value> {
|
||||||
let mut ans = Vec::new();
|
self.tree
|
||||||
for value in self.tree.iter_range(start, Some(end)) {
|
.iter_range(start, Some(end))
|
||||||
ans.push(&value.as_tree_ref().value)
|
.map(|x| &x.as_tree_ref().value)
|
||||||
}
|
|
||||||
ans
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: need double check this method
|
/// TODO: need double check this method
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_range_with_index(&self, start: Index, end: Index) -> Vec<(Index, &Value)> {
|
pub fn get_range_with_index(
|
||||||
let mut ans = Vec::new();
|
&self,
|
||||||
for value in self.tree.iter_range(start, Some(end)) {
|
start: Index,
|
||||||
let value = value.as_tree_ref();
|
end: Index,
|
||||||
ans.push((value.index, &value.value));
|
) -> impl Iterator<Item = (Index, &Value)> {
|
||||||
}
|
self.tree.iter_range(start, Some(end)).map(|x| {
|
||||||
|
let x = x.as_tree_ref();
|
||||||
ans
|
(x.index, &x.value)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in a new issue