Add benchmarks to help optimise result caching

This commit is contained in:
Oliver Hamlet
2018-10-06 13:28:03 +01:00
parent 3404924752
commit f6f51e2ee6
3 changed files with 176 additions and 0 deletions
+35
View File
@@ -52,6 +52,7 @@ impl From<pelite::resources::FindError> for Error {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum GameType {
Tes4,
Tes5,
@@ -84,6 +85,7 @@ impl GameType {
}
}
#[derive(Debug)]
pub struct State {
game_type: GameType,
/// Game Data folder path.
@@ -100,6 +102,39 @@ pub struct State {
condition_cache: RwLock<HashMap<Function, bool>>,
}
impl State {
pub fn new(game_type: GameType, data_path: PathBuf, loot_path: PathBuf) -> Self {
State {
game_type,
data_path,
loot_path,
active_plugins: HashSet::default(),
crc_cache: RwLock::default(),
plugin_versions: HashMap::default(),
condition_cache: RwLock::default(),
}
}
pub fn with_plugin_versions<T: AsRef<str>, V: ToString>(
mut self,
plugin_versions: &[(T, V)],
) -> Self {
self.plugin_versions = plugin_versions
.iter()
.map(|(p, v)| (p.as_ref().to_lowercase(), v.to_string()))
.collect();
self
}
pub fn with_active_plugins<T: AsRef<str>>(mut self, active_plugins: &[T]) -> Self {
self.active_plugins = active_plugins
.into_iter()
.map(|s| s.as_ref().to_lowercase())
.collect();
self
}
}
/// Compound conditions joined by 'or'
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Expression(Vec<CompoundCondition>);