Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: src/collection.js

Issue 329253004: Optimize Map/Set.prototype.forEach (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update count to fix merge issue Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Array = global.Array; 9 // var $Array = global.Array;
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 if (!IS_SET(this)) { 73 if (!IS_SET(this)) {
74 throw MakeTypeError('incompatible_method_receiver', 74 throw MakeTypeError('incompatible_method_receiver',
75 ['Set.prototype.forEach', this]); 75 ['Set.prototype.forEach', this]);
76 } 76 }
77 77
78 if (!IS_SPEC_FUNCTION(f)) { 78 if (!IS_SPEC_FUNCTION(f)) {
79 throw MakeTypeError('called_non_callable', [f]); 79 throw MakeTypeError('called_non_callable', [f]);
80 } 80 }
81 81
82 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); 82 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES);
83 var entry; 83 var key;
84 var stepping = %_DebugCallbackSupportsStepping(f); 84 var stepping = %_DebugCallbackSupportsStepping(f);
85 while (!(entry = %SetIteratorNext(iterator)).done) { 85 while (%SetIteratorHasMore(iterator)) {
86 key = %SetIteratorCurrentKey(iterator);
87 %SetIteratorMoveNext(iterator);
Michael Starzinger 2014/06/23 19:51:52 I am _very_ surprised that this is faster. How are
arv (Not doing code reviews) 2014/06/23 20:31:51 The cost of 1 call vs 3 calls is not so large. Sin
86 if (stepping) %DebugPrepareStepInIfStepping(f); 88 if (stepping) %DebugPrepareStepInIfStepping(f);
87 %_CallFunction(receiver, entry.value, entry.value, this, f); 89 %_CallFunction(receiver, key, key, this, f);
88 } 90 }
89 } 91 }
90 92
91 93
92 // ------------------------------------------------------------------- 94 // -------------------------------------------------------------------
93 95
94 function SetUpSet() { 96 function SetUpSet() {
95 %CheckIsBootstrapping(); 97 %CheckIsBootstrapping();
96 98
97 %SetCode($Set, SetConstructor); 99 %SetCode($Set, SetConstructor);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (!IS_MAP(this)) { 186 if (!IS_MAP(this)) {
185 throw MakeTypeError('incompatible_method_receiver', 187 throw MakeTypeError('incompatible_method_receiver',
186 ['Map.prototype.forEach', this]); 188 ['Map.prototype.forEach', this]);
187 } 189 }
188 190
189 if (!IS_SPEC_FUNCTION(f)) { 191 if (!IS_SPEC_FUNCTION(f)) {
190 throw MakeTypeError('called_non_callable', [f]); 192 throw MakeTypeError('called_non_callable', [f]);
191 } 193 }
192 194
193 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); 195 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES);
194 var entry; 196 var key, value;
195 var stepping = %_DebugCallbackSupportsStepping(f); 197 var stepping = %_DebugCallbackSupportsStepping(f);
196 while (!(entry = %MapIteratorNext(iterator)).done) { 198 while (%MapIteratorHasMore(iterator)) {
199 key = %MapIteratorCurrentKey(iterator);
200 value = %MapIteratorCurrentValue(iterator);
201 %MapIteratorMoveNext(iterator);
197 if (stepping) %DebugPrepareStepInIfStepping(f); 202 if (stepping) %DebugPrepareStepInIfStepping(f);
198 %_CallFunction(receiver, entry.value[1], entry.value[0], this, f); 203 %_CallFunction(receiver, value, key, this, f);
199 } 204 }
200 } 205 }
201 206
202 207
203 // ------------------------------------------------------------------- 208 // -------------------------------------------------------------------
204 209
210
205 function SetUpMap() { 211 function SetUpMap() {
206 %CheckIsBootstrapping(); 212 %CheckIsBootstrapping();
207 213
208 %SetCode($Map, MapConstructor); 214 %SetCode($Map, MapConstructor);
209 %FunctionSetPrototype($Map, new $Object()); 215 %FunctionSetPrototype($Map, new $Object());
210 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); 216 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
211 217
212 %FunctionSetLength(MapForEach, 1); 218 %FunctionSetLength(MapForEach, 1);
213 219
214 // Set up the non-enumerable functions on the Map prototype object. 220 // Set up the non-enumerable functions on the Map prototype object.
215 InstallGetter($Map.prototype, "size", MapGetSizeJS); 221 InstallGetter($Map.prototype, "size", MapGetSizeJS);
216 InstallFunctions($Map.prototype, DONT_ENUM, $Array( 222 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
217 "get", MapGetJS, 223 "get", MapGetJS,
218 "set", MapSetJS, 224 "set", MapSetJS,
219 "has", MapHasJS, 225 "has", MapHasJS,
220 "delete", MapDeleteJS, 226 "delete", MapDeleteJS,
221 "clear", MapClearJS, 227 "clear", MapClearJS,
222 "forEach", MapForEach 228 "forEach", MapForEach
223 )); 229 ));
224 } 230 }
225 231
226 SetUpMap(); 232 SetUpMap();
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698