From f0ee76c27fb1922babcbaa9ce8ef53f3eb15d97b Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 9 Feb 2026 17:43:03 +0100 Subject: [PATCH] refactor(sdk): Remove one `Vec` allocation. `LinkedChunk::push_items_back` expects an `IntoIter`. `EventLinkedChunk::push_live_events` has an `events` of kind `&[Event]`. Using `events.iter().cloned()` instead of `events.to_vec()` not only removes one `Vec` allocation, but it allows the compiler to apply more optimisation. Checking on godbolt.org, I see twice fewer LLVM IR lines, and 2.8x times less ASM code. --- crates/matrix-sdk/src/event_cache/room/events.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/matrix-sdk/src/event_cache/room/events.rs b/crates/matrix-sdk/src/event_cache/room/events.rs index 65acc9b28..a3b45e9f9 100644 --- a/crates/matrix-sdk/src/event_cache/room/events.rs +++ b/crates/matrix-sdk/src/event_cache/room/events.rs @@ -297,7 +297,7 @@ impl EventLinkedChunk { } } - self.chunks.push_items_back(events.to_vec()); + self.chunks.push_items_back(events.iter().cloned()); } /// Finish a network back-pagination for this linked chunk by updating the