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

Side by Side Diff: src/collection-iterator.js

Issue 355663002: Optimize Map/Set.prototype.forEach (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Also get rid of NewIteratorResultObject since there are no more users of it Created 6 years, 5 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 | « src/collection.js ('k') | src/factory.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 7
8 // This file relies on the fact that the following declaration has been made 8 // This file relies on the fact that the following declaration has been made
9 // in runtime.js: 9 // in runtime.js:
10 // var $Set = global.Set; 10 // var $Set = global.Set;
11 // var $Map = global.Map; 11 // var $Map = global.Map;
12 12
13 13
14 function SetIteratorConstructor(set, kind) { 14 function SetIteratorConstructor(set, kind) {
15 %SetIteratorInitialize(this, set, kind); 15 %SetIteratorInitialize(this, set, kind);
16 } 16 }
17 17
18 18
19 function SetIteratorNextJS() { 19 function SetIteratorNextJS() {
20 if (!IS_SET_ITERATOR(this)) { 20 if (!IS_SET_ITERATOR(this)) {
21 throw MakeTypeError('incompatible_method_receiver', 21 throw MakeTypeError('incompatible_method_receiver',
22 ['Set Iterator.prototype.next', this]); 22 ['Set Iterator.prototype.next', this]);
23 } 23 }
24 return %SetIteratorNext(this); 24
25 var value_array = [UNDEFINED, UNDEFINED];
26 var entry = {value: value_array, done: false};
arv (Not doing code reviews) 2014/06/25 20:17:54 I benchmarked this and the following code has no n
27 switch (%SetIteratorNext(this, value_array)) {
28 case 0:
29 entry.value = UNDEFINED;
30 entry.done = true;
31 break;
32 case ITERATOR_KIND_VALUES:
33 entry.value = value_array[0];
34 break;
35 case ITERATOR_KIND_ENTRIES:
36 value_array[1] = value_array[0];
37 entry.value = value_array;
38 break;
39 }
40
41 return entry;
25 } 42 }
26 43
27 44
28 function SetIteratorSymbolIterator() { 45 function SetIteratorSymbolIterator() {
29 return this; 46 return this;
30 } 47 }
31 48
32 49
33 function SetEntries() { 50 function SetEntries() {
34 if (!IS_SET(this)) { 51 if (!IS_SET(this)) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 function MapIteratorSymbolIterator() { 107 function MapIteratorSymbolIterator() {
91 return this; 108 return this;
92 } 109 }
93 110
94 111
95 function MapIteratorNextJS() { 112 function MapIteratorNextJS() {
96 if (!IS_MAP_ITERATOR(this)) { 113 if (!IS_MAP_ITERATOR(this)) {
97 throw MakeTypeError('incompatible_method_receiver', 114 throw MakeTypeError('incompatible_method_receiver',
98 ['Map Iterator.prototype.next', this]); 115 ['Map Iterator.prototype.next', this]);
99 } 116 }
100 return %MapIteratorNext(this); 117
118 var value_array = [UNDEFINED, UNDEFINED];
119 var entry = {value: value_array, done: false};
120 switch (%MapIteratorNext(this, value_array)) {
121 case 0:
122 entry.value = UNDEFINED;
123 entry.done = true;
124 break;
125 case ITERATOR_KIND_KEYS:
126 entry.value = value_array[0];
127 break;
128 case ITERATOR_KIND_VALUES:
129 entry.value = value_array[1];
130 break;
131 case ITERATOR_KIND_ENTRIES:
132 entry.value = value_array;
133 break;
134 }
135
136 return entry;
101 } 137 }
102 138
103 139
104 function MapEntries() { 140 function MapEntries() {
105 if (!IS_MAP(this)) { 141 if (!IS_MAP(this)) {
106 throw MakeTypeError('incompatible_method_receiver', 142 throw MakeTypeError('incompatible_method_receiver',
107 ['Map.prototype.entries', this]); 143 ['Map.prototype.entries', this]);
108 } 144 }
109 return new MapIterator(this, ITERATOR_KIND_ENTRIES); 145 return new MapIterator(this, ITERATOR_KIND_ENTRIES);
110 } 146 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 'entries', MapEntries, 189 'entries', MapEntries,
154 'keys', MapKeys, 190 'keys', MapKeys,
155 'values', MapValues 191 'values', MapValues
156 )); 192 ));
157 193
158 %SetProperty($Map.prototype, symbolIterator, MapEntries, 194 %SetProperty($Map.prototype, symbolIterator, MapEntries,
159 DONT_ENUM); 195 DONT_ENUM);
160 } 196 }
161 197
162 ExtendMapPrototype(); 198 ExtendMapPrototype();
OLDNEW
« no previous file with comments | « src/collection.js ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698