Iterate attr spans in reverse for efficiency
This commit is contained in:
parent
ed9a3b7840
commit
e2b9aa77b9
1 changed files with 4 additions and 4 deletions
|
|
@ -137,6 +137,7 @@ impl<'a> Attrs<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List of text attributes to apply to a line
|
/// List of text attributes to apply to a line
|
||||||
|
//TODO: have this clean up the spans when changes are made
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(Eq, PartialEq)]
|
||||||
pub struct AttrsList<'a> {
|
pub struct AttrsList<'a> {
|
||||||
defaults: Attrs<'a>,
|
defaults: Attrs<'a>,
|
||||||
|
|
@ -176,13 +177,12 @@ impl<'a> AttrsList<'a> {
|
||||||
///
|
///
|
||||||
/// This returns the latest added span that contains the range
|
/// This returns the latest added span that contains the range
|
||||||
pub fn get_span(&self, range: Range<usize>) -> Attrs<'a> {
|
pub fn get_span(&self, range: Range<usize>) -> Attrs<'a> {
|
||||||
let mut attrs = self.defaults;
|
for span in self.spans.iter().rev() {
|
||||||
for span in self.spans.iter() {
|
|
||||||
if range.start >= span.0.start && range.end <= span.0.end {
|
if range.start >= span.0.start && range.end <= span.0.end {
|
||||||
attrs = span.1;
|
return span.1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attrs
|
self.defaults
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Split attributes list at an offset
|
/// Split attributes list at an offset
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue