Skip to content

Commit 618d8e9

Browse files
committed
Optimize sync_to_model to remove from back
Removing from index 0 causes O(n) shift for each removal, making the overall clear operation O(n²). Removing from the back is O(1) per removal.
1 parent 2db42fd commit 618d8e9

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/selection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ impl SelectionManager {
5656

5757
/// Sync the internal selection set to a Slint VecModel
5858
pub fn sync_to_model(&self, model: &VecModel<i32>) {
59-
// Clear and repopulate to ensure exact match
59+
// Clear by removing from the back to avoid O(n²) shifting
6060
while model.row_count() > 0 {
61-
model.remove(0);
61+
model.remove(model.row_count() - 1);
6262
}
6363
for &id in &self.selected {
6464
model.push(id);

0 commit comments

Comments
 (0)