Skip to content

Commit

Permalink
Only re-create elements if the model actually changed
Browse files Browse the repository at this point in the history
Being dirty is not enough

Fixes #7245

ChangeLog: Elements of a `for` now only get re-created if the model is
changed, not if it is only dirty
  • Loading branch information
ogoffart committed Jan 6, 2025
1 parent ba4a363 commit ba07135
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions internal/core/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,15 +895,17 @@ impl<C: RepeatedItemTree + 'static> Repeater<C> {
}

fn model(self: Pin<&Self>) -> ModelRc<C::Data> {
// Safety: Repeater does not implement drop and never allows access to model as mutable
let model = self.data().project_ref().model;

if model.is_dirty() {
*self.data().inner.borrow_mut() = RepeaterInner::default();
self.data().is_dirty.set(true);
let old_model = model.get_internal();
let m = model.get();
let peer = self.project_ref().0.model_peer();
m.model_tracker().attach_peer(peer);
if old_model != m {
*self.data().inner.borrow_mut() = RepeaterInner::default();
self.data().is_dirty.set(true);
let peer = self.project_ref().0.model_peer();
m.model_tracker().attach_peer(peer);
}
m
} else {
model.get()
Expand Down
4 changes: 2 additions & 2 deletions internal/core/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,8 @@ impl<T: Clone> Property<T> {
self.get_internal()
}

/// Get the value without registering any dependencies or executing any binding
fn get_internal(&self) -> T {
/// Get the cached value without registering any dependencies or executing any binding
pub fn get_internal(&self) -> T {
self.handle.access(|_| {
// Safety: PropertyHandle::access ensure that the value is locked
unsafe { (*self.value.get()).clone() }
Expand Down

0 comments on commit ba07135

Please sign in to comment.