From fecd33d172554ad39d1ba8e4ac103d142b668489 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Sat, 9 May 2020 15:25:05 +0200 Subject: [PATCH] Removed one indirection from objects (#386) --- boa/src/builtins/object/mod.rs | 38 +++++++++++++++++----------------- boa/src/builtins/regexp/mod.rs | 2 +- boa/src/builtins/string/mod.rs | 2 +- boa/src/builtins/value/mod.rs | 7 ++----- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/boa/src/builtins/object/mod.rs b/boa/src/builtins/object/mod.rs index ace266767e..2c23f1a9fd 100644 --- a/boa/src/builtins/object/mod.rs +++ b/boa/src/builtins/object/mod.rs @@ -47,13 +47,13 @@ pub struct Object { /// The type of the object. pub kind: ObjectKind, /// Intfiernal Slots - pub internal_slots: Box>, + pub internal_slots: FxHashMap, /// Properties - pub properties: Box>, + pub properties: FxHashMap, /// Symbol Properties - pub sym_properties: Box>, + pub sym_properties: FxHashMap, /// Some rust object that stores internal state - pub state: Option>, + pub state: Option, /// [[Call]] pub call: Option, /// [[Construct]] @@ -338,9 +338,9 @@ impl Object { pub fn default() -> Self { let mut object = Self { kind: ObjectKind::Ordinary, - internal_slots: Box::new(FxHashMap::default()), - properties: Box::new(FxHashMap::default()), - sym_properties: Box::new(FxHashMap::default()), + internal_slots: FxHashMap::default(), + properties: FxHashMap::default(), + sym_properties: FxHashMap::default(), state: None, call: None, construct: None, @@ -354,9 +354,9 @@ impl Object { pub fn function() -> Self { let mut object = Self { kind: ObjectKind::Function, - internal_slots: Box::new(FxHashMap::default()), - properties: Box::new(FxHashMap::default()), - sym_properties: Box::new(FxHashMap::default()), + internal_slots: FxHashMap::default(), + properties: FxHashMap::default(), + sym_properties: FxHashMap::default(), state: None, call: None, construct: None, @@ -396,9 +396,9 @@ impl Object { fn from_boolean(argument: &Value) -> Self { let mut obj = Self { kind: ObjectKind::Boolean, - internal_slots: Box::new(FxHashMap::default()), - properties: Box::new(FxHashMap::default()), - sym_properties: Box::new(FxHashMap::default()), + internal_slots: FxHashMap::default(), + properties: FxHashMap::default(), + sym_properties: FxHashMap::default(), state: None, call: None, construct: None, @@ -413,9 +413,9 @@ impl Object { fn from_number(argument: &Value) -> Self { let mut obj = Self { kind: ObjectKind::Number, - internal_slots: Box::new(FxHashMap::default()), - properties: Box::new(FxHashMap::default()), - sym_properties: Box::new(FxHashMap::default()), + internal_slots: FxHashMap::default(), + properties: FxHashMap::default(), + sym_properties: FxHashMap::default(), state: None, call: None, construct: None, @@ -430,9 +430,9 @@ impl Object { fn from_string(argument: &Value) -> Self { let mut obj = Self { kind: ObjectKind::String, - internal_slots: Box::new(FxHashMap::default()), - properties: Box::new(FxHashMap::default()), - sym_properties: Box::new(FxHashMap::default()), + internal_slots: FxHashMap::default(), + properties: FxHashMap::default(), + sym_properties: FxHashMap::default(), state: None, call: None, construct: None, diff --git a/boa/src/builtins/regexp/mod.rs b/boa/src/builtins/regexp/mod.rs index ff98da5d1a..889aa6d6b9 100644 --- a/boa/src/builtins/regexp/mod.rs +++ b/boa/src/builtins/regexp/mod.rs @@ -81,7 +81,7 @@ pub fn make_regexp(this: &mut Value, args: &[Value], _: &mut Interpreter) -> Res regex_body = body.into(); } ValueData::Object(ref obj) => { - let slots = &*obj.borrow().internal_slots; + let slots = &obj.borrow().internal_slots; if slots.get("RegExpMatcher").is_some() { // first argument is another `RegExp` object, so copy its pattern and flags if let Some(body) = slots.get("OriginalSource") { diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index 3c8855d661..d96bdd3f9f 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -407,7 +407,7 @@ fn get_regex_string(value: &Value) -> String { match value.deref() { ValueData::String(ref body) => body.into(), ValueData::Object(ref obj) => { - let slots = &*obj.borrow().internal_slots; + let slots = &obj.borrow().internal_slots; if slots.get("RegExpMatcher").is_some() { // first argument is another `RegExp` object, so copy its pattern and flags if let Some(body) = slots.get("OriginalSource") { diff --git a/boa/src/builtins/value/mod.rs b/boa/src/builtins/value/mod.rs index 8cb80414d9..4396301cec 100644 --- a/boa/src/builtins/value/mod.rs +++ b/boa/src/builtins/value/mod.rs @@ -393,10 +393,7 @@ impl ValueData { /// Get the internal state of an object. pub fn get_internal_state(&self) -> Option { if let Self::Object(ref obj) = *self { - obj.borrow() - .state - .as_ref() - .map(|state| state.deref().clone()) + obj.borrow().state.as_ref().cloned() } else { None } @@ -534,7 +531,7 @@ impl ValueData { if let Self::Object(ref obj) = *self { obj.borrow_mut() .state - .replace(Box::new(InternalStateCell::new(state))); + .replace(InternalStateCell::new(state)); } }