Author: Stephan <step...@stzal.com>
Branch: 
Changeset: r360:33a38e14a318
Date: 2013-02-21 14:57 +0100
http://bitbucket.org/pypy/lang-js/changeset/33a38e14a318/

Log:    optimized property access

diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -2,7 +2,7 @@
 from rpython.rlib.rarithmetic import intmask
 from rpython.rlib.rfloat import isnan, isinf, NAN, formatd, INFINITY
 from rpython.rlib.objectmodel import enforceargs
-from rpython.rlib import jit
+from rpython.rlib import jit, debug
 
 from js.property_descriptor import PropertyDescriptor, DataPropertyDescriptor, 
AccessorPropertyDescriptor, is_data_descriptor, is_generic_descriptor, 
is_accessor_descriptor
 from js.property import DataProperty, AccessorProperty
@@ -179,7 +179,7 @@
     def __init__(self):
         from js.object_space import newnull
         self._property_map_ = new_map()
-        self._property_slots_ = []
+        self._property_slots_ = debug.make_sure_not_resized([])
 
         self._prototype_ = newnull()
         W_BasicObject.define_own_property(self, u'__proto__', proto_desc)
@@ -242,7 +242,8 @@
         if self._property_map_.not_found(idx):
             return
 
-        del(self._property_slots_[idx])
+        assert idx >= 0
+        self._property_slots_ = self._property_slots_[:idx] + 
self._property_slots_[idx + 1:]
         self._property_map_ = self._property_map_.delete(name)
 
     def _add_prop(self, name, value):
@@ -253,7 +254,7 @@
             idx = self._property_map_.index
 
         if idx >= len(self._property_slots_):
-            self._property_slots_ += ([None] * (1 + idx - 
len(self._property_slots_)))
+            self._property_slots_ = self._property_slots_ + ([None] * (1 + idx 
- len(self._property_slots_)))
 
         self._property_slots_[idx] = value
 
@@ -479,7 +480,7 @@
                     return reject(throw, p)
         # 12
         prop = self._get_prop(p)
-        self._set_prop(p, prop.update_with_descriptor(desc))
+        prop.update_with_descriptor(desc)
 
         # 13
         return True
diff --git a/js/property.py b/js/property.py
--- a/js/property.py
+++ b/js/property.py
@@ -7,8 +7,6 @@
 
 # 8.6.1
 class Property(object):
-    _immutable_fields_ = ['value', 'writable', 'getter', 'setter', 
'enumerable', 'configurable']
-
     def __init__(self, value=None, writable=NOT_SET, getter=None, setter=None, 
enumerable=NOT_SET, configurable=NOT_SET):
         self.value = value
         self.writable = writable
@@ -41,26 +39,18 @@
         assert isinstance(desc, PropertyDescriptor)
 
         if desc.has_set_value():
-            value = desc.value
-        else:
-            value = self.value
+            self.value = desc.value
 
         if desc.has_set_writable():
-            writable = desc.writable
-        else:
-            writable = self.writable
+            self.writable = desc.writable
 
         if desc.has_set_enumerable():
-            enumerable = desc.enumerable
-        else:
-            enumerable = self.enumerable
+            self.enumerable = desc.enumerable
 
         if desc.has_set_configurable():
-            configurable = desc.configurable
-        else:
-            configurable = self.configurable
+            self.configurable = desc.configurable
 
-        return DataProperty(value, writable, enumerable, configurable)
+        return self
 
     def to_property_descriptor(self):
         return DataPropertyDescriptor(self.value, self.writable, 
self.enumerable, self.configurable)
@@ -77,26 +67,18 @@
         assert isinstance(desc, PropertyDescriptor)
 
         if desc.has_set_getter():
-            getter = desc.getter
-        else:
-            getter = self.getter
+            self.getter = desc.getter
 
         if desc.has_set_setter():
-            setter = desc.setter
-        else:
-            setter = self.setter
+            self.setter = desc.setter
 
         if desc.has_set_enumerable():
-            enumerable = desc.enumerable
-        else:
-            enumerable = self.enumerable
+            self.enumerable = desc.enumerable
 
         if desc.has_set_configurable():
-            configurable = desc.configurable
-        else:
-            configurable = self.configurable
+            self.configurable = desc.configurable
 
-        return AccessorProperty(getter, setter, enumerable, configurable)
+        return self
 
     def to_property_descriptor(self):
         return AccessorPropertyDescriptor(self.getter, self.setter, 
self.enumerable, self.configurable)
diff --git a/test/jit_view.py b/test/jit_view.py
--- a/test/jit_view.py
+++ b/test/jit_view.py
@@ -62,6 +62,20 @@
 
         self.run(code, 100)
 
+    def test_simple_object_alloc_loop_in_func_loop(self):
+        code = """
+        function f() {
+            var i = 0;
+            while(i < 100) {
+                i = {foo: i}.foo + 1;
+            }
+            return x.i;
+        }
+        return f();
+        """
+
+        self.run(code, 100)
+
     def test_object_alloc_loop_in_func_loop(self):
         code = """
         function f() {
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to