🏡 index : ~doyle/bin.git

author Jordan Johnson-Doyle <jordan@doyle.la> 2019-02-14 1:24:24.0 +00:00:00
committer Jordan Johnson-Doyle <jordan@doyle.la> 2019-02-14 1:24:24.0 +00:00:00
commit
9c340ea08ce6e3ceeecbce35276b49d082820bda [patch]
tree
c4617cdaecaff465a60f941dc49ef7c0d30cedc9
parent
44d3b3358cb8ab61afaafe6652a2b18df13e38ad
download
9c340ea08ce6e3ceeecbce35276b49d082820bda.tar.gz

Only need to read from BIN_BUFFER_SIZE once



Diff

 src/io.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/io.rs b/src/io.rs
index 6b6a343..f72783a 100644
--- a/src/io.rs
+++ b/src/io.rs
@@ -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();