57
57
import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
58
58
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
59
59
import com .oracle .graal .python .builtins .objects .method .PBuiltinMethod ;
60
- import com .oracle .graal .python .lib .GetNextNode ;
60
+ import com .oracle .graal .python .lib .PyIterNextNode ;
61
61
import com .oracle .graal .python .lib .PyObjectGetItem ;
62
62
import com .oracle .graal .python .lib .PyObjectGetIter ;
63
63
import com .oracle .graal .python .lib .PyObjectLookupAttr ;
68
68
import com .oracle .graal .python .nodes .attributes .LookupCallableSlotInMRONode ;
69
69
import com .oracle .graal .python .nodes .builtins .ListNodes .FastConstructListNode ;
70
70
import com .oracle .graal .python .nodes .call .special .CallVarargsMethodNode ;
71
- import com .oracle .graal .python .nodes .object .BuiltinClassProfiles .IsBuiltinObjectProfile ;
72
71
import com .oracle .graal .python .nodes .object .GetClassNode ;
73
72
import com .oracle .graal .python .runtime .ExecutionContext .IndirectCallContext ;
74
73
import com .oracle .graal .python .runtime .PythonContext ;
@@ -160,20 +159,23 @@ protected static boolean hasIterAttrButNotBuiltin(Node inliningTarget, Object co
160
159
return attr != PNone .NO_VALUE && !(attr instanceof PBuiltinMethod || attr instanceof PBuiltinFunction );
161
160
}
162
161
163
- @ Specialization (guards = {"!isNoValue(arg)" , "!isPDict(arg) || hasIterAttrButNotBuiltin(inliningTarget, arg, getClassNode, lookupIter)" })
162
+ @ Specialization (guards = {"!isNoValue(arg)" , "!isPDict(arg) || hasIterAttrButNotBuiltin(inliningTarget, arg, getClassNode, lookupIter)" }, limit = "2" )
164
163
static HashingStorage updateArg (VirtualFrame frame , Object arg , PKeyword [] kwargs ,
165
164
@ Bind ("this" ) Node inliningTarget ,
166
165
@ SuppressWarnings ("unused" ) @ Exclusive @ Cached GetClassNode getClassNode ,
167
166
@ SuppressWarnings ("unused" ) @ Exclusive @ Cached (parameters = "Iter" ) LookupCallableSlotInMRONode lookupIter ,
168
167
@ Exclusive @ Cached PyObjectLookupAttr lookupKeysAttributeNode ,
169
168
@ Exclusive @ Cached ObjectToArrayPairNode toArrayPair ,
170
- @ Exclusive @ Cached HashingStorageSetItem setHasihngStorageItem ,
171
- @ Exclusive @ Cached HashingStorageAddAllToOther addAllToOther ) {
169
+ @ Exclusive @ Cached HashingStorageSetItem setItem ,
170
+ @ Exclusive @ Cached HashingStorageAddAllToOther addAllToOther ,
171
+ @ Cached InlinedConditionProfile hasKwds ) {
172
172
Object keyAttr = lookupKeysAttributeNode .execute (frame , inliningTarget , arg , T_KEYS );
173
173
ArrayBuilder <KeyValue > elements = toArrayPair .execute (frame , arg , keyAttr );
174
174
HashingStorage storage = PDict .createNewStorage (elements .size () + kwargs .length );
175
- storage = addKeyValuesToStorage (frame , elements , storage , inliningTarget , setHasihngStorageItem );
176
- storage = addKeywordsToStorage (frame , kwargs , storage , inliningTarget , addAllToOther );
175
+ storage = addKeyValuesToStorage (frame , elements , storage , inliningTarget , setItem );
176
+ if (hasKwds .profile (inliningTarget , kwargs .length > 0 )) {
177
+ storage = addAllToOther .execute (frame , inliningTarget , new KeywordsStorage (kwargs ), storage );
178
+ }
177
179
return storage ;
178
180
}
179
181
@@ -197,15 +199,6 @@ public final HashingStorage unionCached(HashingStorage other, HashingStorageCopy
197
199
return addAllToOther .executeCached (null , other , newStore );
198
200
}
199
201
200
- public static HashingStorage addKeywordsToStorage (VirtualFrame frame , PKeyword [] kwargs , HashingStorage storage ,
201
- Node inliningTarget ,
202
- HashingStorageAddAllToOther addAllToOther ) {
203
- if (kwargs .length > 0 ) {
204
- return addAllToOther .execute (frame , inliningTarget , new KeywordsStorage (kwargs ), storage );
205
- }
206
- return storage ;
207
- }
208
-
209
202
@ ValueType
210
203
protected static final class KeyValue {
211
204
final Object key ;
@@ -219,22 +212,22 @@ private KeyValue(Object key, Object value) {
219
212
220
213
public static HashingStorage addKeyValuesToStorage (VirtualFrame frame , ArrayBuilder <KeyValue > elements , HashingStorage storage ,
221
214
Node inliningTarget ,
222
- HashingStorageSetItem setHashingStorageItem ) {
215
+ HashingStorageSetItem setItem ) {
223
216
for (int i = 0 ; i < elements .size (); i ++) {
224
217
Object key = elements .get (i ).key ;
225
218
Object value = elements .get (i ).value ;
226
- storage = setHashingStorageItem .execute (frame , inliningTarget , storage , key , value );
219
+ storage = setItem .execute (frame , inliningTarget , storage , key , value );
227
220
}
228
221
return storage ;
229
222
}
230
223
231
224
public static HashingStorage addKeyValuesToStorage (VirtualFrame frame , PDict self , Object other , Object keyAttr ,
232
225
Node inliningTarget ,
233
226
ObjectToArrayPairNode toArrayPair ,
234
- HashingStorageSetItem setHashingStorageItem ) {
227
+ HashingStorageSetItem setItem ) {
235
228
ArrayBuilder <KeyValue > elements = toArrayPair .execute (frame , other , keyAttr );
236
229
HashingStorage storage = self .getDictStorage ();
237
- return addKeyValuesToStorage (frame , elements , storage , inliningTarget , setHashingStorageItem );
230
+ return addKeyValuesToStorage (frame , elements , storage , inliningTarget , setItem );
238
231
}
239
232
240
233
// partial impl dict_update_arg
@@ -252,23 +245,17 @@ public abstract static class ObjectToArrayPairNode extends PNodeWithContext {
252
245
static ArrayBuilder <KeyValue > partialMerge (VirtualFrame frame , Object mapping , Object keyAttr ,
253
246
@ Bind ("this" ) Node inliningTarget ,
254
247
@ Shared @ Cached PyObjectGetIter getIter ,
255
- @ Shared @ Cached GetNextNode nextNode ,
248
+ @ Shared @ Cached ( neverDefault = false ) PyIterNextNode nextNode ,
256
249
@ Shared @ Cached PyObjectGetItem getItemNode ,
257
- @ Shared @ Cached IsBuiltinObjectProfile errorProfile ,
258
250
@ Cached CallVarargsMethodNode callKeysMethod ) {
259
251
// We don't need to pass self as the attribute object has it already.
260
252
Object keysIterable = callKeysMethod .execute (frame , keyAttr , EMPTY_OBJECT_ARRAY , EMPTY_KEYWORDS );
261
253
Object keysIt = getIter .execute (frame , inliningTarget , keysIterable );
262
254
ArrayBuilder <KeyValue > elements = new ArrayBuilder <>();
263
- while (true ) {
264
- try {
265
- Object keyObj = nextNode .execute (frame , keysIt );
266
- Object valueObj = getItemNode .execute (frame , inliningTarget , mapping , keyObj );
267
- elements .add (new KeyValue (keyObj , valueObj ));
268
- } catch (PException e ) {
269
- e .expectStopIteration (inliningTarget , errorProfile );
270
- break ;
271
- }
255
+ Object keyObj ;
256
+ while ((keyObj = nextNode .execute (frame , keysIt )) != null ) {
257
+ Object valueObj = getItemNode .execute (frame , inliningTarget , mapping , keyObj );
258
+ elements .add (new KeyValue (keyObj , valueObj ));
272
259
}
273
260
return elements ;
274
261
}
@@ -278,19 +265,17 @@ static ArrayBuilder<KeyValue> partialMerge(VirtualFrame frame, Object mapping, O
278
265
static ArrayBuilder <KeyValue > partialMergeFromSeq2 (VirtualFrame frame , Object iterable , @ SuppressWarnings ("unused" ) PNone keyAttr ,
279
266
@ Bind ("this" ) Node inliningTarget ,
280
267
@ Shared @ Cached PyObjectGetIter getIter ,
281
- @ Shared @ Cached GetNextNode nextNode ,
268
+ @ Shared @ Cached ( neverDefault = false ) PyIterNextNode nextNode ,
282
269
@ Shared @ Cached PyObjectGetItem getItemNode ,
283
- @ Shared @ Cached IsBuiltinObjectProfile errorProfile ,
284
270
@ Cached FastConstructListNode createListNode ,
285
271
@ Cached LenNode seqLenNode ,
286
272
@ Cached PRaiseNode .Lazy raise ,
287
- @ Cached InlinedConditionProfile lengthTwoProfile ,
288
- @ Exclusive @ Cached IsBuiltinObjectProfile isTypeErrorProfile ) throws PException {
273
+ @ Cached InlinedConditionProfile lengthTwoProfile ) throws PException {
289
274
Object it = getIter .execute (frame , inliningTarget , iterable );
290
275
ArrayBuilder <KeyValue > elements = new ArrayBuilder <>();
276
+ Object next ;
291
277
try {
292
- while (true ) {
293
- Object next = nextNode .execute (frame , it );
278
+ while ((next = nextNode .execute (frame , it )) != null ) {
294
279
PSequence element = createListNode .execute (frame , inliningTarget , next );
295
280
assert element != null ;
296
281
// This constructs a new list using the builtin type. So, the object cannot
@@ -305,11 +290,7 @@ static ArrayBuilder<KeyValue> partialMergeFromSeq2(VirtualFrame frame, Object it
305
290
elements .add (new KeyValue (key , value ));
306
291
}
307
292
} catch (PException e ) {
308
- if (isTypeErrorProfile .profileException (inliningTarget , e , TypeError )) {
309
- throw raise .get (inliningTarget ).raise (TypeError , ErrorMessages .CANNOT_CONVERT_DICT_UPDATE_SEQ , elements .size ());
310
- } else {
311
- e .expectStopIteration (inliningTarget , errorProfile );
312
- }
293
+ throw raise .get (inliningTarget ).raise (TypeError , ErrorMessages .CANNOT_CONVERT_DICT_UPDATE_SEQ , elements .size ());
313
294
}
314
295
return elements ;
315
296
}
0 commit comments