Skip to content

Commit

Permalink
Use Box<str> instead of String in Environment
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed May 10, 2021
1 parent 4b00cc6 commit e47bd59
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
10 changes: 5 additions & 5 deletions boa/src/environment/declarative_environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct DeclarativeEnvironmentRecordBinding {
/// declarations contained within its scope.
#[derive(Debug, Trace, Finalize, Clone)]
pub struct DeclarativeEnvironmentRecord {
pub env_rec: FxHashMap<String, DeclarativeEnvironmentRecordBinding>,
pub env_rec: FxHashMap<Box<str>, DeclarativeEnvironmentRecordBinding>,
pub outer_env: Option<Environment>,
}

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions boa/src/environment/global_environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct GlobalEnvironmentRecord {
pub object_record: ObjectEnvironmentRecord,
pub global_this_binding: GcObject,
pub declarative_record: DeclarativeEnvironmentRecord,
pub var_names: FxHashSet<String>,
pub var_names: FxHashSet<Box<str>>,
}

impl GlobalEnvironmentRecord {
Expand Down Expand Up @@ -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(())
}
Expand Down
11 changes: 1 addition & 10 deletions boa/src/environment/lexical_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e47bd59

Please sign in to comment.