Bug 912079 part 4 - Optimize SuppressDeletedPropertyHelper when the property matches the iterator's previous one. r=anba
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 26 Apr 2018 18:41:30 +0200
changeset 460803 ac68dde791890802488aa0f4129b2458ec520395
parent 460802 acf9cda9b84dae2aeb52c508e73fbce68c280da1
child 460804 5644d7852eb834b07ba125662af23fad75013d19
push id165
push userfmarier@mozilla.com
push dateMon, 30 Apr 2018 23:50:51 +0000
reviewersanba
bugs912079
milestone61.0a1
Bug 912079 part 4 - Optimize SuppressDeletedPropertyHelper when the property matches the iterator's previous one. r=anba
js/src/vm/Iteration.cpp
--- a/js/src/vm/Iteration.cpp
+++ b/js/src/vm/Iteration.cpp
@@ -1200,16 +1200,27 @@ js::UnwindIteratorForUncatchableExceptio
 
 static bool
 SuppressDeletedProperty(JSContext* cx, NativeIterator* ni, HandleObject obj,
                         Handle<JSFlatString*> str)
 {
     if (ni->obj != obj)
         return true;
 
+    // Optimization for the following common case:
+    //
+    //    for (var p in o) {
+    //        delete o[p];
+    //    }
+    //
+    // Note that usually both strings will be atoms so we only check for pointer
+    // equality here.
+    if (ni->props_cursor > ni->begin() && ni->props_cursor[-1] == str)
+        return true;
+
     while (true) {
         bool restart = false;
 
         // Check whether id is still to come.
         GCPtrFlatString* const props_cursor = ni->props_cursor;
         GCPtrFlatString* const props_end = ni->end();
         for (GCPtrFlatString* idp = props_cursor; idp < props_end; ++idp) {
             // Common case: both strings are atoms.