From 8b15361a847d3429dc86f67b3776ac22b3f2e270 Mon Sep 17 00:00:00 2001 From: daa Date: Mon, 11 Sep 2017 22:00:26 +0300 Subject: [PATCH] Small optimization --- src/ui_model/line.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/ui_model/line.rs b/src/ui_model/line.rs index ba52ef7..608d829 100644 --- a/src/ui_model/line.rs +++ b/src/ui_model/line.rs @@ -186,18 +186,17 @@ impl Line { self.cell_to_item[cell_idx] } - pub fn item_len_from_idx(&self, mut start_idx: usize) -> usize { - let mut len = 1; - start_idx += 1; + pub fn item_len_from_idx(&self, start_idx: usize) -> usize { + debug_assert!(start_idx < self.line.len()); - while start_idx < self.item_line.len() && self.is_binded_to_item(start_idx) && - self.item_line[start_idx].is_none() - { - start_idx += 1; - len += 1; + let item_idx = self.cell_to_item(start_idx); + + if item_idx >= 0 { + let item_idx = item_idx as usize; + self.item_line[item_idx].as_ref().unwrap().cells_count - (start_idx - item_idx) + } else { + 1 } - - len } #[inline]