Skip to content

Commit a1847b0

Browse files
committed
HashingStorage-s clear has to return new storage instance on .clear
1 parent c7de0a6 commit a1847b0

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ private static Object runNode(DynamicObjectStorage self, Object key, Object acc,
341341
@ExportMessage
342342
@TruffleBoundary
343343
public HashingStorage clear() {
344-
store.setShapeAndResize(store.getShape(), EMPTY_SHAPE);
345-
store.updateShape();
346-
return this;
344+
return new DynamicObjectStorage();
347345
}
348346

349347
@Override

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,16 @@ static HashingStorage delItemWithStateWithSideEffect(EconomicMapStorage self, Ob
372372
static class Clear {
373373

374374
@Specialization(guards = "!hasSideEffect(self)")
375-
static HashingStorage clear(EconomicMapStorage self) {
376-
self.map.clear();
377-
return self;
375+
static HashingStorage clear(@SuppressWarnings("unused") EconomicMapStorage self) {
376+
return create();
378377
}
379378

380379
@Specialization
381380
static HashingStorage clearWithSideEffect(EconomicMapStorage self,
382381
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic lookup,
383382
@Exclusive @Cached CallUnaryMethodNode callNode) {
384383
if (self.map.size() == 0) {
385-
return self;
384+
return create();
386385
}
387386
Object[] entries = new Object[self.map.size() * 2];
388387
MapCursor<DictKey, Object> cursor = self.map.getEntries();
@@ -399,7 +398,7 @@ static HashingStorage clearWithSideEffect(EconomicMapStorage self,
399398
callNode.executeObject(lookup.execute(o, __DEL__), o);
400399
}
401400
}
402-
return self;
401+
return create();
403402
}
404403

405404
}

0 commit comments

Comments
 (0)