0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-21 21:48:21 -05:00

perf: replace Vec<T> with Box<T> & initialize vectors with capacity by default (#603)

This commit is contained in:
neon_arch 2024-09-05 22:03:23 +05:30
parent 4bb6c5e90b
commit 39af9096ef

View File

@ -16,7 +16,7 @@ const REDIS_PIPELINE_SIZE: usize = 3;
/// connect to. /// connect to.
pub struct RedisCache { pub struct RedisCache {
/// It stores a pool of connections ready to be used. /// It stores a pool of connections ready to be used.
connection_pool: Vec<ConnectionManager>, connection_pool: Box<[ConnectionManager]>,
/// It stores the size of the connection pool (in other words the number of /// It stores the size of the connection pool (in other words the number of
/// connections that should be stored in the pool). /// connections that should be stored in the pool).
pool_size: u8, pool_size: u8,
@ -58,13 +58,13 @@ impl RedisCache {
})); }));
} }
let mut outputs = Vec::new(); let mut outputs = Vec::with_capacity(tasks.len());
for task in tasks { for task in tasks {
outputs.push(task.await??); outputs.push(task.await??);
} }
let redis_cache = RedisCache { let redis_cache = RedisCache {
connection_pool: outputs, connection_pool: outputs.into_boxed_slice(),
pool_size, pool_size,
current_connection: Default::default(), current_connection: Default::default(),
cache_ttl, cache_ttl,