Skip to content

Commit a85307d

Browse files
committed
RangeBuiltins: fix __getitem__ / sq_item builtin
1 parent cf7ac0e commit a85307d

File tree

1 file changed

+9
-4
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range

1 file changed

+9
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,22 @@ protected static boolean allNone(PObjectSlice slice) {
339339
return slice.getStart() == PNone.NONE && slice.getStop() == PNone.NONE && slice.getStep() == PNone.NONE;
340340
}
341341

342+
protected static boolean isNotSlice(Object value) {
343+
return !(value instanceof PSlice);
344+
}
345+
342346
@Specialization(guards = "allNone(slice)")
343347
Object doPRangeObj(PRange range, @SuppressWarnings("unused") PObjectSlice slice) {
344348
return range;
345349
}
346350

347-
@Specialization(guards = "canBeInteger(idx)")
348-
Object doPRange(PIntRange primary, Object idx) {
349-
return primary.getIntItemNormalized(normalize.execute(idx, primary.getIntLength()));
351+
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()", guards = "isNotSlice(idx)")
352+
Object doPRange(PIntRange primary, Object idx,
353+
@CachedLibrary(value = "idx") PythonObjectLibrary pol) {
354+
return primary.getIntItemNormalized(normalize.execute(pol.asSize(idx), primary.getIntLength()));
350355
}
351356

352-
@Specialization(guards = "canBeInteger(idx)")
357+
@Specialization(guards = "isNotSlice(idx)")
353358
Object doPRange(PBigRange self, Object idx,
354359
@Cached CastToJavaBigIntegerNode toBigInt) {
355360
return factory().createInt(self.getBigIntItemNormalized(computeBigRangeItem(self, idx, toBigInt)));

0 commit comments

Comments
 (0)