[fractal] Improve performance of find-visible algorithm



commit 74e17cb0cab9d783313647961af4b2e4faf585e5
Author: Sonja Heinze <sonjaleaheinze gmail com>
Date:   Thu Feb 6 18:18:30 2020 +0100

    Improve performance of find-visible algorithm
    
    This commit improves the performance of the algorithm that finds all
    messages that are in sight in the room history scrolled window.

 fractal-gtk/src/widgets/room_history.rs | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index 12ae29bc..ab5f170e 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -127,16 +127,22 @@ impl List {
         if len == 0 {
             return indices;
         }
-        if let Some(visible_index) = self.find_visible_index((0, len - 1)) {
-            indices.push(visible_index);
-            let upper = self.list.iter().enumerate().skip(visible_index + 1);
+
+        let sw = self.view.get_scrolled_window();
+        let visible_index = match get_rel_position(&sw, &self.list[0]) {
+            RelativePosition::InSight => Some(0),
+            _ => self.find_visible_index((1, len - 1)),
+        };
+        if let Some(visible) = visible_index {
+            indices.push(visible);
+            let upper = self.list.iter().enumerate().skip(visible + 1);
             self.add_while_visible(&mut indices, upper);
             let lower = self
                 .list
                 .iter()
                 .enumerate()
                 .rev()
-                .skip(self.list.len() - visible_index);
+                .skip(self.list.len() - visible);
             self.add_while_visible(&mut indices, lower);
         }
         indices


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]