From fee5b84ccbe04d2b59c02d8354810a18ff86cc55 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Tue, 15 Oct 2024 17:06:32 +0200 Subject: [PATCH] backend/multi: Advance index on backend_commit wlr_multi_backend sorts the states it is given and tries to perform sequential backend-wide commits for each sub-backend with the states that belong to it. It did not manage the index correctly for the next iteration, so given N states for a backend it would perform N backend-wide commits. Clarify the logic by calculating a length rather than an end pointer and update the index after each iteration. --- backend/multi/backend.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/multi/backend.c b/backend/multi/backend.c index 82e96fd4..239524f1 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -126,22 +126,24 @@ static bool commit(struct wlr_backend *backend, qsort(by_backend, states_len, sizeof(by_backend[0]), compare_output_state_backend); bool ok = true; - for (size_t i = 0; i < states_len; i++) { + for (size_t i = 0; i < states_len;) { struct wlr_backend *sub = by_backend[i].output->backend; - size_t j = i; - while (j < states_len && by_backend[j].output->backend == sub) { - j++; + size_t len = 1; + while (i + len < states_len && + by_backend[i + len].output->backend == sub) { + len++; } if (test_only) { - ok = wlr_backend_test(sub, &by_backend[i], j - i); + ok = wlr_backend_test(sub, &by_backend[i], len); } else { - ok = wlr_backend_commit(sub, &by_backend[i], j - i); + ok = wlr_backend_commit(sub, &by_backend[i], len); } if (!ok) { break; } + i += len; } free(by_backend);