--- /dev/null
+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])
+ }
+}
use core::{PackageId, Registry, SourceId, Summary, Dependency};
use core::PackageIdSpec;
+use core::interning::InternedString;
use util::config::Config;
use util::Graph;
use util::errors::{CargoResult, CargoError};
warnings: RcList<String>,
}
-type Activations = HashMap<String, HashMap<SourceId, Rc<Vec<Summary>>>>;
+type Activations = HashMap<InternedString, HashMap<SourceId, Rc<Vec<Summary>>>>;
/// Builds the list of all packages required to build the first argument.
pub fn resolve(summaries: &[(Summary, Method)],
method: &Method) -> CargoResult<bool> {
let id = summary.package_id();
let prev = self.activations
- .entry(id.name().to_string())
+ .entry(InternedString::new(id.name()))
.or_insert_with(HashMap::new)
.entry(id.source_id().clone())
.or_insert_with(||Rc::new(Vec::new()));
}
fn prev_active(&self, dep: &Dependency) -> &[Summary] {
- self.activations.get(dep.name())
+ self.activations.get(&InternedString::new(dep.name()))
.and_then(|v| v.get(dep.source_id()))
.map(|v| &v[..])
.unwrap_or(&[])
}
fn is_active(&self, id: &PackageId) -> bool {
- self.activations.get(id.name())
+ self.activations.get(&InternedString::new(id.name()))
.and_then(|v| v.get(id.source_id()))
.map(|v| v.iter().any(|s| s.package_id() == id))
.unwrap_or(false)