Prematurely optimize RoomBuffer's memory usage
This commit is contained in:
@ -44,6 +44,7 @@ libc = "0.2.148"
|
|||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
nonempty = { version = "0.8.1", features = ["serialize"] }
|
nonempty = { version = "0.8.1", features = ["serialize"] }
|
||||||
signal-hook = "0.3.17"
|
signal-hook = "0.3.17"
|
||||||
|
smallvec = "1.11.1"
|
||||||
|
|
||||||
# Matrix
|
# Matrix
|
||||||
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", rev = "91e7f2f7224b8ada17ab639d60da10dad98aeaf9", features = ["eyre", "markdown"] }
|
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", rev = "91e7f2f7224b8ada17ab639d60da10dad98aeaf9", features = ["eyre", "markdown"] }
|
||||||
|
@ -158,7 +158,7 @@ impl App {
|
|||||||
for client in &self.clients {
|
for client in &self.clients {
|
||||||
for room in client.joined_rooms() {
|
for room in client.joined_rooms() {
|
||||||
self.buffers.push(Box::new(RoomBuffer::new(
|
self.buffers.push(Box::new(RoomBuffer::new(
|
||||||
vec![client.clone()],
|
[client.clone()],
|
||||||
room.room_id().to_owned(),
|
room.room_id().to_owned(),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,23 @@
|
|||||||
use matrix_sdk::ruma::OwnedRoomId;
|
use matrix_sdk::ruma::OwnedRoomId;
|
||||||
use matrix_sdk::Client;
|
use matrix_sdk::Client;
|
||||||
use matrix_sdk::Room;
|
use matrix_sdk::Room;
|
||||||
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use super::Buffer;
|
use super::Buffer;
|
||||||
|
|
||||||
pub struct RoomBuffer {
|
pub struct RoomBuffer {
|
||||||
clients: Vec<Client>,
|
// It's unlikely users will join the same room with more than one account;
|
||||||
|
// avoid a useless heap allocation for the usual case.
|
||||||
|
clients: SmallVec<[Client; 1]>,
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RoomBuffer {
|
impl RoomBuffer {
|
||||||
pub fn new(clients: Vec<Client>, room_id: OwnedRoomId) -> Self {
|
pub fn new<Clients: IntoIterator<Item = Client>>(clients: Clients, room_id: OwnedRoomId) -> Self {
|
||||||
RoomBuffer { clients, room_id }
|
RoomBuffer {
|
||||||
|
clients: clients.into_iter().collect(),
|
||||||
|
room_id,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user