Only need to read from BIN_BUFFER_SIZE once

This commit is contained in:
Jordan Johnson-Doyle 2019-02-14 01:24:24 +00:00
parent 44d3b3358c
commit 9c340ea08c
No known key found for this signature in database
GPG key ID: A95F87B578CE79B6

View file

@ -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();