Change context storage from BTreeMap to HashMap

This commit is contained in:
Jeff 2024-06-17 17:39:44 -04:00
parent cddf199156
commit dd062e63f1

View File

@ -1,5 +1,5 @@
use std::{ use std::{
collections::BTreeMap, collections::HashMap,
sync::{Arc, RwLock, RwLockReadGuard}, sync::{Arc, RwLock, RwLockReadGuard},
}; };
@ -12,7 +12,7 @@ use crate::{
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Context<'a> { pub struct Context<'a> {
variables: Arc<RwLock<BTreeMap<Identifier, (VariableData, UsageData)>>>, variables: Arc<RwLock<HashMap<Identifier, (VariableData, UsageData)>>>,
parent: Option<&'a Context<'a>>, parent: Option<&'a Context<'a>>,
is_clean: Arc<RwLock<bool>>, is_clean: Arc<RwLock<bool>>,
} }
@ -20,7 +20,7 @@ pub struct Context<'a> {
impl<'a> Context<'a> { impl<'a> Context<'a> {
pub fn new(parent: Option<&'a Context>) -> Self { pub fn new(parent: Option<&'a Context>) -> Self {
Self { Self {
variables: Arc::new(RwLock::new(BTreeMap::new())), variables: Arc::new(RwLock::new(HashMap::new())),
parent, parent,
is_clean: Arc::new(RwLock::new(true)), is_clean: Arc::new(RwLock::new(true)),
} }
@ -32,7 +32,7 @@ impl<'a> Context<'a> {
pub fn inner( pub fn inner(
&self, &self,
) -> Result<RwLockReadGuard<BTreeMap<Identifier, (VariableData, UsageData)>>, RwLockPoisonError> ) -> Result<RwLockReadGuard<HashMap<Identifier, (VariableData, UsageData)>>, RwLockPoisonError>
{ {
Ok(self.variables.read()?) Ok(self.variables.read()?)
} }