Skip to content

Commit d463043

Browse files
committed
Narrow long to int if possible for IntSequenceStorage.
1 parent b130138 commit d463043

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,20 @@ protected static void doInt(IntSequenceStorage storage, int idx, int value) {
12081208
storage.setIntItemNormalized(idx, value);
12091209
}
12101210

1211+
@Specialization(rewriteOn = OverflowException.class)
1212+
protected static void doIntL(IntSequenceStorage storage, int idx, long value) throws OverflowException {
1213+
storage.setIntItemNormalized(idx, PInt.intValueExact(value));
1214+
}
1215+
1216+
@Specialization(replaces = "doIntL")
1217+
protected static void doIntLOvf(IntSequenceStorage storage, int idx, long value) {
1218+
try {
1219+
storage.setIntItemNormalized(idx, PInt.intValueExact(value));
1220+
} catch (OverflowException e) {
1221+
throw new SequenceStoreException(value);
1222+
}
1223+
}
1224+
12111225
@Specialization(guards = "!value.isNative()")
12121226
protected static void doInt(IntSequenceStorage storage, int idx, PInt value) {
12131227
try {

0 commit comments

Comments
 (0)