Skip to content

Commit 7a7a5b4

Browse files
committed
Adding specialization for fast path in PInt case and correcting return type of error handler in CastToIndexNode.
1 parent 883c75b commit 7a7a5b4

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,13 @@ boolean startsWith(String self, String prefix, long start, long end) {
538538
return doIt(self, prefix, correctIndex(start, self), correctIndex(end, self));
539539
}
540540

541-
@Specialization
541+
@Specialization (rewriteOn = ArithmeticException.class)
542542
boolean startsWith(String self, String prefix, PInt start, @SuppressWarnings("unused") PNone end) {
543+
return startsWith(self, prefix, start.intValueExact(), self.length());
544+
}
545+
546+
@Specialization
547+
boolean startsWithPIntOvf(String self, String prefix, PInt start, @SuppressWarnings("unused") PNone end) {
543548
return doIt(self, prefix, correctIndex(start, self), self.length());
544549
}
545550

@@ -563,11 +568,16 @@ boolean startsWith(String self, PTuple prefix, long start, long end) {
563568
return doIt(self, prefix, correctIndex(start, self), correctIndex(end, self));
564569
}
565570

566-
@Specialization
571+
@Specialization (rewriteOn = ArithmeticException.class)
567572
boolean startsWith(String self, PTuple prefix, PInt start, @SuppressWarnings("unused") PNone end) {
573+
return startsWith(self, prefix, start.intValueExact(), end);
574+
}
575+
576+
@Specialization
577+
boolean startsWithPIntOvf(String self, PTuple prefix, PInt start, @SuppressWarnings("unused") PNone end) {
568578
return doIt(self, prefix, correctIndex(start, self), self.length());
569579
}
570-
580+
571581
@Specialization
572582
boolean startsWith(String self, PTuple prefix, @SuppressWarnings("unused") PNone start, @SuppressWarnings("unused") PNone end) {
573583
return startsWith(self, prefix, 0, self.length());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToIndexNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public abstract class CastToIndexNode extends PNodeWithContext {
7070

7171
private final PythonBuiltinClassType errorType;
7272
private final boolean recursive;
73-
private final Function<Object, Byte> typeErrorHandler;
73+
private final Function<Object, Integer> typeErrorHandler;
7474

75-
protected CastToIndexNode(PythonBuiltinClassType errorType, boolean recursive, Function<Object, Byte> typeErrorHandler) {
75+
protected CastToIndexNode(PythonBuiltinClassType errorType, boolean recursive, Function<Object, Integer> typeErrorHandler) {
7676
this.errorType = errorType;
7777
this.recursive = recursive;
7878
this.typeErrorHandler = typeErrorHandler;
@@ -166,7 +166,7 @@ public static CastToIndexNode createOverflow() {
166166
return CastToIndexNodeGen.create(OverflowError, true, null);
167167
}
168168

169-
public static CastToIndexNode create(PythonBuiltinClassType errorType, Function<Object, Byte> typeErrorHandler) {
169+
public static CastToIndexNode create(PythonBuiltinClassType errorType, Function<Object, Integer> typeErrorHandler) {
170170
return CastToIndexNodeGen.create(errorType, true, typeErrorHandler);
171171
}
172172
}

0 commit comments

Comments
 (0)