Skip to content

Commit 7cc2910

Browse files
committed
Small speed up of find node.
1 parent 522a9e9 commit 7cc2910

File tree

1 file changed

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

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,14 @@ private CastToIndexNode getEndNode() {
542542
}
543543

544544
private SliceInfo computeSlice(int length, long start, long end) {
545-
int step = start < end ? 1 : -1;
546-
PSlice tmpSlice = factory().createSlice(getStartNode().execute(start), getEndNode().execute(end), step);
545+
PSlice tmpSlice = factory().createSlice(getStartNode().execute(start), getEndNode().execute(end), 1);
547546
return tmpSlice.computeIndices(length);
548547
}
549548

550549
private SliceInfo computeSlice(int length, Object startO, Object endO) {
551550
int start = startO == PNone.NO_VALUE || startO == PNone.NONE ? 0 : getStartNode().execute(startO);
552551
int end = endO == PNone.NO_VALUE || endO == PNone.NONE ? length : getEndNode().execute(endO);
553-
int step = start < end ? 1 : -1;
554-
PSlice tmpSlice = factory().createSlice(start, end, step);
552+
PSlice tmpSlice = factory().createSlice(start, end, 1);
555553
return tmpSlice.computeIndices(length);
556554
}
557555

@@ -564,24 +562,36 @@ Object find(String self, String str, @SuppressWarnings("unused") PNone start, @S
564562
Object find(String self, String str, long start, @SuppressWarnings("unused") PNone end) {
565563
int len = self.length();
566564
SliceInfo info = computeSlice(len, start, len);
565+
if (info.length == 0) {
566+
return -1;
567+
}
567568
return findWithBounds(self, str, info.start, info.stop);
568569
}
569570

570571
@Specialization
571572
Object find(String self, String str, @SuppressWarnings("unused") PNone start, long end) {
572573
SliceInfo info = computeSlice(self.length(), 0, end);
574+
if (info.length == 0) {
575+
return -1;
576+
}
573577
return findWithBounds(self, str, info.start, info.stop);
574578
}
575579

576580
@Specialization
577581
Object find(String self, String str, long start, long end) {
578582
SliceInfo info = computeSlice(self.length(), start, end);
583+
if (info.length == 0) {
584+
return -1;
585+
}
579586
return findWithBounds(self, str, info.start, info.stop);
580587
}
581588

582589
@Specialization
583590
Object findGeneric(String self, String str, Object start, Object end) throws ArithmeticException {
584591
SliceInfo info = computeSlice(self.length(), start, end);
592+
if (info.length == 0) {
593+
return -1;
594+
}
585595
return findWithBounds(self, str, info.start, info.stop);
586596
}
587597

0 commit comments

Comments
 (0)