feat(sdk): Create vectors with correct capacity to avoid reallocations.

`updated_rooms` and `updated_lists` can be created with an initial
capacity. Doing so will avoid reallocations if the vector is too small.
This commit is contained in:
Ivan Enderlin
2023-04-06 10:49:15 +02:00
parent 91dc87808d
commit c07b060080

View File

@@ -354,9 +354,11 @@ impl SlidingSync {
}
let update_summary = {
let mut updated_rooms = Vec::new();
let mut rooms_map = self.inner.rooms.write().unwrap();
// Update the rooms.
let mut updated_rooms = Vec::with_capacity(sliding_sync_response.rooms.len());
for (room_id, mut room_data) in sliding_sync_response.rooms.into_iter() {
// `sync_response` contains the rooms with decrypted events if any, so look at
// the timeline events here first if the room exists.
@@ -390,7 +392,8 @@ impl SlidingSync {
updated_rooms.push(room_id);
}
let mut updated_lists = Vec::new();
// Update the lists.
let mut updated_lists = Vec::with_capacity(sliding_sync_response.lists.len());
for (name, updates) in sliding_sync_response.lists {
let Some(list) = lists.get_mut(&name) else {