forked from rust-lang/cargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In a test on rust-lang#4810 (comment) Before we got to 5000000 ticks in ~72 sec After we got to 5000000 ticks in ~65 sec
- Loading branch information
Showing
5 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::fmt; | ||
use std::sync::RwLock; | ||
use std::collections::HashMap; | ||
|
||
lazy_static! { | ||
static ref STRING_CASHE: RwLock<(Vec<String>, HashMap<String, usize>)> = | ||
RwLock::new((Vec::new(), HashMap::new())); | ||
} | ||
|
||
#[derive(Eq, PartialEq, Hash, Clone, Copy)] | ||
pub struct InternedString { | ||
id: usize | ||
} | ||
|
||
impl InternedString { | ||
pub fn new(str: &str) -> InternedString { | ||
let (ref mut str_from_id, ref mut id_from_str) = *STRING_CASHE.write().unwrap(); | ||
if let Some(&id) = id_from_str.get(str) { | ||
return InternedString { id }; | ||
} | ||
str_from_id.push(str.to_string()); | ||
id_from_str.insert(str.to_string(), str_from_id.len() - 1); | ||
return InternedString { id: str_from_id.len() - 1 } | ||
} | ||
// pub fn to_inner(&self) -> String { | ||
// STRING_CASHE.read().unwrap().0[self.id].to_string() | ||
// } | ||
} | ||
|
||
impl fmt::Debug for InternedString { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "InternedString {{ {} }}", STRING_CASHE.read().unwrap().0[self.id]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters