mux: avoid over-invalidating in a couple of cases

This commit is contained in:
Wez Furlong committed 2020-01-09 08:47:29 -08:00
1 parent 0f5eec0244
commit c8635c07f3
1 file changed
+28 -10
+28 -10
View File
@@ -321,6 +321,9 @@ enum LineEntry {
// as needing rendering because we are also in the process of
// downloading a newer version from the server
DirtyAndFetching(Line, Instant),
// We have a local copy but it is stale and will need to be
// fetched again
Stale(Line),
}
impl LineEntry {
@@ -330,6 +333,7 @@ impl LineEntry {
Self::Dirty(_) => ("Dirty", None),
Self::Fetching(since) => ("Fetching", Some(*since)),
Self::DirtyAndFetching(_, since) => ("DirtyAndFetching", Some(*since)),
Self::Stale(_) => ("Stale", None),
}
}
}
@@ -402,19 +406,14 @@ impl RenderableInner {
let prior = self.lines.pop(&stable_row);
let prior_kind = prior.as_ref().map(|e| e.kind());
if !fetchable {
if prior.is_some() {
log::trace!(
"row {} {:?} -> unset due to dirty and out of viewport",
stable_row,
prior_kind,
);
}
self.make_stale(stable_row);
continue;
}
to_fetch.add(stable_row);
let entry = match prior {
Some(LineEntry::Fetching(_)) | None => LineEntry::Fetching(now),
Some(LineEntry::DirtyAndFetching(old, ..))
| Some(LineEntry::Stale(old))
| Some(LineEntry::Dirty(old))
| Some(LineEntry::Line(old)) => LineEntry::DirtyAndFetching(old, now),
};
@@ -434,13 +433,25 @@ impl RenderableInner {
log::trace!("exceeded throttle, drop {:?}", to_fetch);
for r in to_fetch.iter() {
for stable_row in r.clone() {
self.lines.pop(&stable_row);
self.make_stale(stable_row);
}
}
}
}
}
fn make_stale(&mut self, stable_row: StableRowIndex) {
match self.lines.pop(&stable_row) {
Some(LineEntry::Dirty(old))
| Some(LineEntry::Stale(old))
| Some(LineEntry::Line(old))
| Some(LineEntry::DirtyAndFetching(old, _)) => {
self.lines.put(stable_row, LineEntry::Stale(old));
}
Some(LineEntry::Fetching(_)) | None => {}
}
}
fn put_line(
&mut self,
stable_row: StableRowIndex,
@@ -463,16 +474,18 @@ impl RenderableInner {
log::trace!("row {} fetch done -> Dirty", stable_row,);
LineEntry::Dirty(line)
}
e => {
Some(e) => {
// It changed since we started: leave it alone!
log::trace!(
"row {} {:?} changed since fetch started at {:?}, so leave it be",
stable_row,
e.map(|e| e.kind()),
e.kind(),
fetch_start
);
self.lines.put(stable_row, e);
return;
}
None => return,
}
} else {
if let Some(LineEntry::Line(prior)) = self.lines.pop(&stable_row) {
@@ -621,6 +634,11 @@ impl Renderable for RenderableState {
result.push(Line::with_width(inner.dimensions.cols));
LineEntry::Fetching(then)
}
Some(LineEntry::Stale(line)) => {
result.push(line.clone());
to_fetch.add(idx);
LineEntry::DirtyAndFetching(line, now)
}
None => {
result.push(Line::with_width(inner.dimensions.cols));
to_fetch.add(idx);