mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-07 07:27:45 -04:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user