From ae83fd629d1d45939f7ba1d4e8996f3dd2177bc5 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Sat, 2 Nov 2024 02:12:35 +0100 Subject: [PATCH] store more property objects in vecs --- crates/dash_middle/src/util.rs | 10 ++++++++++ crates/dash_vm/src/dispatch.rs | 30 ++++++++++++++--------------- crates/dash_vm/src/js_std/object.rs | 4 ++-- crates/dash_vm/src/json/parser.rs | 3 ++- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/crates/dash_middle/src/util.rs b/crates/dash_middle/src/util.rs index fa10cf22..183ce976 100644 --- a/crates/dash_middle/src/util.rs +++ b/crates/dash_middle/src/util.rs @@ -308,3 +308,13 @@ macro_rules! with { $code }}; } + +#[macro_export] +macro_rules! closure { + ($(clone($clone_binding:ident))*; $closure:expr) => { + { + $(let $clone_binding = $clone_binding.clone();)* + $closure + } + }; +} diff --git a/crates/dash_vm/src/dispatch.rs b/crates/dash_vm/src/dispatch.rs index bd1d7431..cdfdda55 100755 --- a/crates/dash_vm/src/dispatch.rs +++ b/crates/dash_vm/src/dispatch.rs @@ -531,7 +531,6 @@ mod handlers { use dash_middle::iterator_with::{InfallibleIteratorWith, IteratorWith}; use dash_middle::parser::statement::{Asyncness, FunctionKind as ParserFunctionKind}; use handlers::extract::{extract, ForwardSequence, FrontIteratorWith}; - use hashbrown::hash_map::Entry; use if_chain::if_chain; use smallvec::SmallVec; use std::ops::{Add, ControlFlow, Div, Mul, Rem, Sub}; @@ -546,7 +545,8 @@ mod handlers { use crate::value::function::generator::GeneratorFunction; use crate::value::function::user::UserFunction; use crate::value::function::{adjust_stack_from_flat_call, Function, FunctionKind}; - use crate::value::object::{NamedObject, Object, ObjectMap, PropertyKey, PropertyValue, PropertyValueKind}; + use crate::value::object::{NamedObject, Object, PropertyKey, PropertyValue, PropertyValueKind}; + use crate::value::object_map::ObjectMap; use crate::value::ops::conversions::ValueConversion; use crate::value::ops::equality; use crate::value::primitive::Number; @@ -1499,26 +1499,26 @@ mod handlers { let mut obj = ObjectMap::default(); while let Some(property) = iter.next(&mut cx) { match property? { - ObjectProperty::Static { key, value } => drop(obj.insert(key, value)), - ObjectProperty::Getter { key, value } => match obj.entry(key) { - Entry::Occupied(mut entry) => match &mut entry.get_mut().kind { - PropertyValueKind::Static(_) => drop(entry.insert(PropertyValue::getter_default(value))), + ObjectProperty::Static { key, value } => obj.insert(key, value), + ObjectProperty::Getter { key, value } => obj.entry(key).modify_or_insert( + |prop| match &mut prop.kind { + PropertyValueKind::Static(_) => *prop = PropertyValue::getter_default(value), PropertyValueKind::Trap { get, .. } => *get = Some(value), }, - Entry::Vacant(entry) => drop(entry.insert(PropertyValue::getter_default(value))), - }, - ObjectProperty::Setter { key, value } => match obj.entry(key) { - Entry::Occupied(mut entry) => match &mut entry.get_mut().kind { - PropertyValueKind::Static(_) => drop(entry.insert(PropertyValue::setter_default(value))), + || PropertyValue::getter_default(value), + ), + ObjectProperty::Setter { key, value } => obj.entry(key).modify_or_insert( + |prop| match &mut prop.kind { + PropertyValueKind::Static(_) => *prop = PropertyValue::setter_default(value), PropertyValueKind::Trap { set, .. } => *set = Some(value), }, - Entry::Vacant(entry) => drop(entry.insert(PropertyValue::setter_default(value))), - }, + || PropertyValue::setter_default(value), + ), ObjectProperty::Spread(value) => { if let ValueKind::Object(object) = value.unpack() { for key in object.own_keys(&mut cx.scope)? { let key = PropertyKey::from_value(&mut cx.scope, key)?; - let value = object.get_property(&mut cx, key.clone())?.root(&mut cx.scope); + let value = object.get_property(&mut cx, key)?.root(&mut cx.scope); obj.insert(key, PropertyValue::static_default(value)); } } @@ -1545,7 +1545,7 @@ mod handlers { match property { ObjectProperty::Static { key, value } => target.set_property(&mut cx.scope, key, value)?, ObjectProperty::Getter { key, value } | ObjectProperty::Setter { key, value } => { - let prop = target.get_property_descriptor(&mut cx.scope, key.clone())?; + let prop = target.get_property_descriptor(&mut cx.scope, key)?; let prop = match prop { Some(mut prop) => { if let PropertyValueKind::Trap { get, set } = &mut prop.kind { diff --git a/crates/dash_vm/src/js_std/object.rs b/crates/dash_vm/src/js_std/object.rs index 0e90b513..9972b9ba 100644 --- a/crates/dash_vm/src/js_std/object.rs +++ b/crates/dash_vm/src/js_std/object.rs @@ -187,7 +187,7 @@ pub fn assign(cx: CallContext) -> Result { let source = source.to_object(cx.scope)?; for key in source.own_keys(cx.scope)? { let key = PropertyKey::from_value(cx.scope, key)?; - let desc = source.get_own_property(cx.scope, key.clone()).root(cx.scope)?; + let desc = source.get_own_property(cx.scope, key).root(cx.scope)?; to.set_property(cx.scope, key, PropertyValue::static_default(desc))?; } } @@ -199,7 +199,7 @@ pub fn entries(cx: CallContext) -> Result { let obj = cx.args.first().unwrap_or_undefined().to_object(cx.scope)?; for key in obj.own_keys(cx.scope)? { let key = PropertyKey::from_value(cx.scope, key)?; - let value = obj.get_own_property(cx.scope, key.clone()).root(cx.scope)?; + let value = obj.get_own_property(cx.scope, key).root(cx.scope)?; let entry = Array::from_vec( cx.scope, vec![ diff --git a/crates/dash_vm/src/json/parser.rs b/crates/dash_vm/src/json/parser.rs index 65ebe388..65b72c57 100644 --- a/crates/dash_vm/src/json/parser.rs +++ b/crates/dash_vm/src/json/parser.rs @@ -6,7 +6,8 @@ use dash_middle::util; use crate::localscope::LocalScope; use crate::value::array::Array; -use crate::value::object::{NamedObject, ObjectMap, PropertyKey, PropertyValue}; +use crate::value::object::{NamedObject, PropertyKey, PropertyValue}; +use crate::value::object_map::ObjectMap; use crate::value::Value; /// An error that occurred during parsing JSON