From 563408df6f76a04b24b3ceeeb6fefde7baf1a62d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 19 Feb 2018 07:34:36 -0800 Subject: [PATCH] micro optimization for scroll_up --- term/src/screen.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/term/src/screen.rs b/term/src/screen.rs index cb7ef2d0c..7a07e37ed 100644 --- a/term/src/screen.rs +++ b/term/src/screen.rs @@ -215,11 +215,18 @@ impl Screen { } } - for _ in 0..num_rows { - self.lines.insert( - phys_scroll.end - lines_removed, - Line::new(self.physical_cols), - ); + if scroll_region.end as usize == self.physical_rows { + // It's cheaper to push() than it is insert() at the end + for _ in 0..num_rows { + self.lines.push(Line::new(self.physical_cols)); + } + } else { + for _ in 0..num_rows { + self.lines.insert( + phys_scroll.end - lines_removed, + Line::new(self.physical_cols), + ); + } } }