mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-01 20:31:27 +00:00
Reduce the amount of re-creation of cells in repeaters when the model changes (#1954)
Re-use the cells but mark them as dirty, instead of re-creating them every time. In the included test-case that provides behavior that's more intuitive.
This commit is contained in:
parent
958cafc357
commit
1162ebbb79
4 changed files with 126 additions and 7 deletions
|
|
@ -1299,7 +1299,14 @@ public:
|
|||
void ensure_updated(const Parent *parent) const
|
||||
{
|
||||
if (model.is_dirty()) {
|
||||
auto preserved_data = inner ? std::make_optional(std::move(inner->data)) : std::nullopt;
|
||||
inner = std::make_shared<RepeaterInner>();
|
||||
if (auto data = preserved_data) {
|
||||
inner->data = std::move(*data);
|
||||
for (auto &&compo_with_state : inner->data) {
|
||||
compo_with_state.state = RepeaterInner::State::Dirty;
|
||||
}
|
||||
}
|
||||
if (auto m = model.get()) {
|
||||
m->attach_peer(inner);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue