Skip to content

Commit 80ee185

Browse files
committed
PythonObjectDictStorage: update internal size based on shape checks
1 parent c4ed648 commit 80ee185

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,11 @@ public HashingStorage copy(Equivalence eq) {
228228

229229
public static final class PythonObjectDictStorage extends DynamicObjectStorage {
230230
private int size = -1;
231+
private Shape shape;
231232

232233
public PythonObjectDictStorage(DynamicObject store) {
233234
super(store);
235+
shape = store.getShape();
234236
}
235237

236238
@Override
@@ -245,41 +247,18 @@ public Iterator<Object> iterator() {
245247

246248
@Override
247249
public int length() {
248-
if (size == -1) {
249-
CompilerAsserts.neverPartOfCompilation();
250+
CompilerAsserts.neverPartOfCompilation();
251+
if (shape != getStore().getShape()) {
250252
size = 0;
251253
for (@SuppressWarnings("unused")
252254
Object ignored : getKeysIterable()) {
253255
size += 1;
254256
}
257+
shape = getStore().getShape();
255258
}
256259
return size;
257260
}
258261

259-
@Override
260-
public void setItem(Object key, Object value, Equivalence eq) {
261-
CompilerAsserts.neverPartOfCompilation();
262-
super.setItem(key, value, eq);
263-
if (value != PNone.NO_VALUE) {
264-
size += 1;
265-
}
266-
}
267-
268-
@Override
269-
public boolean remove(Object key, Equivalence eq) {
270-
CompilerAsserts.neverPartOfCompilation();
271-
if (getStore().get(key) != PNone.NO_VALUE) {
272-
size -= 1;
273-
}
274-
return super.remove(key, eq);
275-
}
276-
277-
@Override
278-
public void clear() {
279-
super.clear();
280-
size = 0;
281-
}
282-
283262
@Override
284263
public boolean hasKey(Object key, Equivalence eq) {
285264
CompilerAsserts.neverPartOfCompilation();

0 commit comments

Comments
 (0)