Skip to content

Commit 2e10683

Browse files
qunaibitcosminbasca
authored andcommitted
Clean up
1 parent 130b21a commit 2e10683

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private boolean eqInt(PIntRange range, int len, int start, int step) {
237237
len, start, step);
238238
}
239239

240-
private boolean eqInt(int llen, int lstart, int lstep, int rlen, int rstart, int rstep) {
240+
private static boolean eqInt(int llen, int lstart, int lstep, int rlen, int rstart, int rstep) {
241241
if (llen != rlen) {
242242
return false;
243243
}
@@ -276,10 +276,6 @@ protected boolean canBeIntRange(PBigRange range, PythonObjectLibrary pol) {
276276
return pol.canBeIndex(range.getPIntLength()) && pol.canBeIndex(range.getPIntStart()) && pol.canBeIndex(range.getPIntStep());
277277
}
278278

279-
protected boolean canBeIntRange(Object len, Object start, Object step, PythonObjectLibrary pol) {
280-
return pol.canBeIndex(len) && pol.canBeIndex(start) && pol.canBeIndex(step);
281-
}
282-
283279
@Specialization
284280
boolean eqIntInt(PIntRange left, PIntRange right) {
285281
if (left == right) {
@@ -348,16 +344,15 @@ Object doPRangeObj(PRange range, @SuppressWarnings("unused") PObjectSlice slice)
348344
return range;
349345
}
350346

351-
@Specialization(guards = "canBeNumber(idx)")
347+
@Specialization(guards = "canBeInteger(idx)")
352348
Object doPRange(PIntRange primary, Object idx) {
353349
return primary.getIntItemNormalized(normalize.execute(idx, primary.getIntLength()));
354350
}
355351

356-
@Specialization(guards = "canBeNumber(idx)")
352+
@Specialization(guards = "canBeInteger(idx)")
357353
Object doPRange(PBigRange self, Object idx,
358354
@Cached CastToJavaBigIntegerNode toBigInt) {
359-
BigInteger i = computeBigRangeItem(self, idx, toBigInt);
360-
return factory().createInt(self.getBigIntItemNormalized(i));
355+
return factory().createInt(self.getBigIntItemNormalized(computeBigRangeItem(self, idx, toBigInt)));
361356
}
362357

363358
@TruffleBoundary
@@ -411,9 +406,7 @@ Object doPRangeObjWithSlowPath(PIntRange range, PSlice slice,
411406
SliceInfo info = compute.execute(slice, range.getIntLength());
412407
return createRange(info, rStart, rStep, lenOfRangeNode);
413408
} catch (PException pe) {
414-
if (!profileError.profileException(pe, PythonBuiltinClassType.OverflowError)) {
415-
throw pe;
416-
}
409+
pe.expect(PythonBuiltinClassType.OverflowError, profileError);
417410
// pass
418411
} catch (CannotCastException | ArithmeticException e) {
419412
// pass
@@ -440,9 +433,7 @@ Object doPRangePSliceSlowPath(PBigRange range, PSlice slice,
440433
SliceInfo info = compute.execute(slice, lib.asSize(range.getLength()));
441434
return createRange(info, rStart, rStep, lenOfRangeNode);
442435
} catch (PException pe) {
443-
if (!profileError.profileException(pe, PythonBuiltinClassType.OverflowError)) {
444-
throw pe;
445-
}
436+
pe.expect(PythonBuiltinClassType.OverflowError, profileError);
446437
// pass
447438
} catch (CannotCastException | ArithmeticException e) {
448439
// pass
@@ -610,7 +601,7 @@ boolean containsSlowNum(PBigRange self, PInt other,
610601
return containsBigInt(self, other.getValue());
611602
}
612603

613-
@Specialization(guards = "!canBeNumber(elem) || !isBuiltinPInt(elem, isBuiltin)")
604+
@Specialization(guards = "!canBeInteger(elem) || !isBuiltinPInt(elem, isBuiltin)")
614605
boolean containsIterator(VirtualFrame frame, PRange self, Object elem,
615606
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
616607
@Cached GetIteratorExpressionNode.GetIteratorNode getIterator,
@@ -685,7 +676,7 @@ int doFastRange(VirtualFrame frame, PIntRange self, int elem,
685676
throw raise(ValueError, ErrorMessages.D_IS_NOT_IN_RANGE, elem);
686677
}
687678

688-
@Specialization(guards = "canBeNumber(elem)", limit = "getCallSiteInlineCacheMaxDepth()")
679+
@Specialization(guards = "canBeInteger(elem)", limit = "getCallSiteInlineCacheMaxDepth()")
689680
Object doFastRangeGeneric(VirtualFrame frame, PIntRange self, Object elem,
690681
@Cached ContainsNode containsNode,
691682
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
@@ -705,7 +696,7 @@ Object doFastRangeGeneric(VirtualFrame frame, PIntRange self, Object elem,
705696
throw raise(ValueError, ErrorMessages.IS_NOT_IN_RANGE, elem);
706697
}
707698

708-
@Specialization(guards = "canBeNumber(elem)")
699+
@Specialization(guards = "canBeInteger(elem)")
709700
Object doLongRange(VirtualFrame frame, PBigRange self, Object elem,
710701
@Cached ContainsNode containsNode,
711702
@Cached CastToJavaBigIntegerNode castToBigInt) {
@@ -729,7 +720,7 @@ static boolean maySideEffect(PythonObject o, LookupInheritedAttributeNode.Dynami
729720
* XXX: (mq) currently sys.maxsize in {@link SysModuleBuiltins#MAXSIZE} is
730721
* {@link Integer#MAX_VALUE}.
731722
*/
732-
@Specialization(guards = "!canBeNumber(elem)")
723+
@Specialization(guards = "!canBeInteger(elem)")
733724
Object containsIterator(VirtualFrame frame, PIntRange self, Object elem,
734725
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
735726
@Cached GetIteratorExpressionNode.GetIteratorNode getIterator,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public abstract class RangeNodes {
7070
public abstract static class CreateBigRangeNode extends Node {
7171
public abstract PBigRange execute(Object start, Object stop, Object step, PythonObjectFactory factory);
7272

73+
@TruffleBoundary
7374
private static void checkStepZero(BigInteger stepBI, PRaiseNode raise) {
7475
if (stepBI.compareTo(BigInteger.ZERO) == 0) {
7576
throw raise.raise(ValueError, ARG_MUST_NOT_BE_ZERO, "range()", 3);
@@ -197,7 +198,7 @@ PBigRange doIntRange(PIntRange range, PythonObjectFactory factory,
197198
}
198199

199200
@Specialization
200-
PBigRange doBigRange(PBigRange range, PythonObjectFactory factory) {
201+
PBigRange doBigRange(PBigRange range, @SuppressWarnings("unused") PythonObjectFactory factory) {
201202
return range;
202203
}
203204

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public static boolean isAnyPythonObject(Object obj) {
353353
return obj instanceof PythonAbstractObject;
354354
}
355355

356-
public static boolean canBeNumber(Object idx) {
356+
public static boolean canBeInteger(Object idx) {
357357
return isBoolean(idx) || isInteger(idx) || isPInt(idx);
358358
}
359359

0 commit comments

Comments
 (0)