From e47bd59a4fece1e4607cb096256c79d10134b937 Mon Sep 17 00:00:00 2001 From: HalidOdat Date: Mon, 3 May 2021 22:35:48 +0200 Subject: [PATCH] Use Box instead of String in Environment --- boa/src/environment/declarative_environment_record.rs | 10 +++++----- boa/src/environment/global_environment_record.rs | 6 +++--- boa/src/environment/lexical_environment.rs | 11 +---------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/boa/src/environment/declarative_environment_record.rs b/boa/src/environment/declarative_environment_record.rs index e809baf4431..6ca3c3918ff 100644 --- a/boa/src/environment/declarative_environment_record.rs +++ b/boa/src/environment/declarative_environment_record.rs @@ -34,7 +34,7 @@ pub struct DeclarativeEnvironmentRecordBinding { /// declarations contained within its scope. #[derive(Debug, Trace, Finalize, Clone)] pub struct DeclarativeEnvironmentRecord { - pub env_rec: FxHashMap, + pub env_rec: FxHashMap, DeclarativeEnvironmentRecordBinding>, pub outer_env: Option, } @@ -65,14 +65,14 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord { ) -> Result<()> { if !allow_name_reuse { assert!( - !self.env_rec.contains_key(&name), + !self.env_rec.contains_key(name.as_str()), "Identifier {} has already been declared", name ); } self.env_rec.insert( - name, + name.into_boxed_str(), DeclarativeEnvironmentRecordBinding { value: None, can_delete: deletion, @@ -90,13 +90,13 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord { _context: &mut Context, ) -> Result<()> { assert!( - !self.env_rec.contains_key(&name), + !self.env_rec.contains_key(name.as_str()), "Identifier {} has already been declared", name ); self.env_rec.insert( - name, + name.into_boxed_str(), DeclarativeEnvironmentRecordBinding { value: None, can_delete: true, diff --git a/boa/src/environment/global_environment_record.rs b/boa/src/environment/global_environment_record.rs index c8de613bc46..2c6c83baf72 100644 --- a/boa/src/environment/global_environment_record.rs +++ b/boa/src/environment/global_environment_record.rs @@ -27,7 +27,7 @@ pub struct GlobalEnvironmentRecord { pub object_record: ObjectEnvironmentRecord, pub global_this_binding: GcObject, pub declarative_record: DeclarativeEnvironmentRecord, - pub var_names: FxHashSet, + pub var_names: FxHashSet>, } impl GlobalEnvironmentRecord { @@ -119,8 +119,8 @@ impl GlobalEnvironmentRecord { } let var_declared_names = &mut self.var_names; - if !var_declared_names.contains(&name) { - var_declared_names.insert(name); + if !var_declared_names.contains(name.as_str()) { + var_declared_names.insert(name.into_boxed_str()); } Ok(()) } diff --git a/boa/src/environment/lexical_environment.rs b/boa/src/environment/lexical_environment.rs index 3e27ad44fc0..fdf4b8a97bc 100644 --- a/boa/src/environment/lexical_environment.rs +++ b/boa/src/environment/lexical_environment.rs @@ -60,16 +60,7 @@ impl fmt::Display for EnvironmentError { } } -impl error::Error for EnvironmentError { - fn description(&self) -> &str { - &self.details - } - - fn cause(&self) -> Option<&dyn error::Error> { - // Generic error, underlying cause isn't tracked. - None - } -} +impl error::Error for EnvironmentError {} impl LexicalEnvironment { pub fn new(global: GcObject) -> Self {