Skip to content

Commit

Permalink
Mutex instead of just using write on a RwLock
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Jun 8, 2018
1 parent 2d3bef4 commit d6d5758
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/cargo/core/interning.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Serialize, Serializer};

use std::fmt;
use std::sync::RwLock;
use std::sync::Mutex;
use std::collections::HashSet;
use std::str;
use std::ptr;
Expand All @@ -14,8 +14,8 @@ pub fn leak(s: String) -> &'static str {
}

lazy_static! {
static ref STRING_CACHE: RwLock<HashSet<&'static str>> =
RwLock::new(HashSet::new());
static ref STRING_CACHE: Mutex<HashSet<&'static str>> =
Mutex::new(HashSet::new());
}

#[derive(Clone, Copy)]
Expand All @@ -33,7 +33,7 @@ impl Eq for InternedString {}

impl InternedString {
pub fn new(str: &str) -> InternedString {
let mut cache = STRING_CACHE.write().unwrap();
let mut cache = STRING_CACHE.lock().unwrap();
let s = cache.get(str).map(|&s| s).unwrap_or_else(|| {
let s = leak(str.to_string());
cache.insert(s);
Expand Down

0 comments on commit d6d5758

Please sign in to comment.