Only need to read from BIN_BUFFER_SIZE once
This commit is contained in:
parent
44d3b3358c
commit
9c340ea08c
1 changed files with 3 additions and 3 deletions
|
@ -9,6 +9,7 @@ use std::cell::RefCell;
|
|||
|
||||
lazy_static! {
|
||||
static ref ENTRIES: RwLock<LinkedHashMap<String, String>> = RwLock::new(LinkedHashMap::new());
|
||||
static ref BUFFER_SIZE: usize = env::var("BIN_BUFFER_SIZE").map(|f| f.parse::<usize>().unwrap()).unwrap_or(1000usize);
|
||||
}
|
||||
|
||||
/// Ensures `ENTRIES` is less than the size of `BIN_BUFFER_SIZE`. If it isn't then
|
||||
|
@ -17,10 +18,9 @@ lazy_static! {
|
|||
/// During the purge, `ENTRIES` is locked and the current thread will block.
|
||||
fn purge_old() {
|
||||
let entries_len = ENTRIES.read().unwrap().len();
|
||||
let buffer_size = env::var("BIN_BUFFER_SIZE").map(|f| f.parse::<usize>().unwrap()).unwrap_or(1000usize);
|
||||
|
||||
if entries_len > buffer_size {
|
||||
let to_remove = entries_len - buffer_size;
|
||||
if entries_len > *BUFFER_SIZE {
|
||||
let to_remove = entries_len - *BUFFER_SIZE;
|
||||
|
||||
let mut entries = ENTRIES.write().unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue