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:
Simon Hausmann 2022-12-06 18:43:55 +01:00 committed by GitHub
parent 958cafc357
commit 1162ebbb79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 126 additions and 7 deletions

View file

@ -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);
}