Skip to content

Commit f462ff5

Browse files
committed
dict init: split into 2 specializations with rewrite on unmodifiable storage exception
1 parent 6254cd6 commit f462ff5

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,17 @@ public void doPDict(PDict self, PDict iterable, @SuppressWarnings("unused") PKey
300300
self.setDictStorage(iterable.getDictStorage().copy(HashingStorage.DEFAULT_EQIVALENCE));
301301
}
302302

303-
@Specialization(guards = {"!isNoValue(iterable)", "!isEmpty(kwargs)"})
303+
@Specialization(guards = {"!isNoValue(iterable)", "!isEmpty(kwargs)"}, rewriteOn = HashingStorage.UnmodifiableStorageException.class)
304304
public void doPDictKwargs(PDict self, PDict iterable, PKeyword[] kwargs,
305-
@Cached("create()") UnionNode unionNode) {
306-
HashingStorage dictStorage;
307-
try {
308-
dictStorage = iterable.getDictStorage().copy(HashingStorage.DEFAULT_EQIVALENCE);
309-
dictStorage.addAll(new KeywordsStorage(kwargs));
310-
} catch (HashingStorage.UnmodifiableStorageException e) {
311-
dictStorage = unionNode.execute(iterable.getDictStorage(), new KeywordsStorage(kwargs));
312-
}
305+
@Cached("create()") UnionNode unionNode) {
306+
HashingStorage dictStorage = unionNode.execute(iterable.getDictStorage(), new KeywordsStorage(kwargs));
307+
self.setDictStorage(dictStorage);
308+
}
309+
310+
@Specialization(guards = {"!isNoValue(iterable)", "!isEmpty(kwargs)"})
311+
public void doPDictKwargs(PDict self, PDict iterable, PKeyword[] kwargs) {
312+
HashingStorage dictStorage = iterable.getDictStorage().copy(HashingStorage.DEFAULT_EQIVALENCE);
313+
dictStorage.addAll(new KeywordsStorage(kwargs));
313314
self.setDictStorage(dictStorage);
314315
}
315316

0 commit comments

Comments
 (0)