Skip to content

Commit 5594a50

Browse files
committed
PEMap: set max initial capacity to 2MB if requested initial cap exceeds default initial capacity
1 parent 695b883 commit 5594a50

File tree

1 file changed

+12
-1
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ final class PEMap implements Iterable<DictKey> {
6666
*/
6767
private static final int INITIAL_CAPACITY = 4;
6868

69+
/**
70+
* Initial number of key/value pair entries that is allocated in the first entries array if the
71+
* requested size is too large. Set to 2 MB
72+
*/
73+
private static final int OBJ_ARRAY_SIZE_1_MB = 131072;
74+
private static final int MAX_INITIAL_CAPACITY = OBJ_ARRAY_SIZE_1_MB * 2;
75+
6976
/**
7077
* Maximum number of entries that are moved linearly forward if a key is removed.
7178
*/
@@ -146,7 +153,11 @@ private PEMap(int initialCapacity, boolean isSet, boolean hasSideEffect) {
146153

147154
private void init(int size) {
148155
if (size > INITIAL_CAPACITY) {
149-
entries = new Object[(size << 1) < 0 ? MAX_ELEMENT_COUNT : size << 1];
156+
int cap = size << 1;
157+
if (cap < 0 || cap > MAX_INITIAL_CAPACITY) {
158+
cap = MAX_INITIAL_CAPACITY;
159+
}
160+
entries = new Object[cap];
150161
}
151162
}
152163

0 commit comments

Comments
 (0)