Make SelectionsCollection::disjoint_anchor_ranges return an iterator (#22948)

This helps discourage unnecessary collection to Vec

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-01-10 02:37:46 -07:00 committed by GitHub
parent 690ad29ba9
commit 1b44398967
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 31 deletions

View file

@ -88,6 +88,12 @@ impl SelectionsCollection {
self.disjoint.clone()
}
pub fn disjoint_anchor_ranges(&self) -> impl Iterator<Item = Range<Anchor>> {
// Mapping the Arc slice would borrow it, whereas indexing captures it.
let disjoint = self.disjoint_anchors();
(0..disjoint.len()).map(move |ix| disjoint[ix].range())
}
pub fn pending_anchor(&self) -> Option<Selection<Anchor>> {
self.pending
.as_ref()
@ -317,13 +323,6 @@ impl SelectionsCollection {
self.all(cx).last().unwrap().clone()
}
pub fn disjoint_anchor_ranges(&self) -> Vec<Range<Anchor>> {
self.disjoint_anchors()
.iter()
.map(|s| s.start..s.end)
.collect()
}
#[cfg(any(test, feature = "test-support"))]
pub fn ranges<D: TextDimension + Ord + Sub<D, Output = D> + std::fmt::Debug>(
&self,