@@ -216,6 +216,40 @@ public abstract static class FindNode extends PNodeWithContext {
216
216
217
217
public abstract int execute (VirtualFrame frame , PIBytesLike bytes , Object sub , Object starting , Object ending );
218
218
219
+ public abstract int execute (VirtualFrame frame , PIBytesLike bytes , int sub , Object starting , Object ending );
220
+
221
+ public abstract int execute (VirtualFrame frame , PIBytesLike bytes , int sub , int starting , Object ending );
222
+
223
+ public abstract int execute (VirtualFrame frame , PIBytesLike bytes , int sub , int starting , int ending );
224
+
225
+ @ Specialization
226
+ int find (VirtualFrame frame , PIBytesLike primary , PIBytesLike sub , int starting , int ending ) {
227
+ SequenceStorage haystack = primary .getSequenceStorage ();
228
+ int len1 = haystack .length ();
229
+
230
+ SequenceStorage needle = sub .getSequenceStorage ();
231
+ int len2 = needle .length ();
232
+
233
+ int start = getNormalizeIndexNode ().execute (starting , len1 );
234
+ int end = getNormalizeIndexNode ().execute (ending , len1 );
235
+
236
+ return findSubSequence (frame , haystack , len1 , needle , len2 , start , end );
237
+ }
238
+
239
+ @ Specialization
240
+ int find (VirtualFrame frame , PIBytesLike primary , PIBytesLike sub , int starting , Object ending ) {
241
+ SequenceStorage haystack = primary .getSequenceStorage ();
242
+ int len1 = haystack .length ();
243
+
244
+ SequenceStorage needle = sub .getSequenceStorage ();
245
+ int len2 = needle .length ();
246
+
247
+ int start = getNormalizeIndexNode ().execute (starting , len1 );
248
+ int end = getNormalizeIndexNode ().execute (ending , len1 );
249
+
250
+ return findSubSequence (frame , haystack , len1 , needle , len2 , start , end );
251
+ }
252
+
219
253
@ Specialization
220
254
int find (VirtualFrame frame , PIBytesLike primary , PIBytesLike sub , Object starting , Object ending ) {
221
255
SequenceStorage haystack = primary .getSequenceStorage ();
@@ -227,6 +261,11 @@ int find(VirtualFrame frame, PIBytesLike primary, PIBytesLike sub, Object starti
227
261
int start = getNormalizeIndexNode ().execute (starting , len1 );
228
262
int end = getNormalizeIndexNode ().execute (ending , len1 );
229
263
264
+ return findSubSequence (frame , haystack , len1 , needle , len2 , start , end );
265
+ }
266
+
267
+ private int findSubSequence (VirtualFrame frame , SequenceStorage haystack , int len1 , SequenceStorage needle , int len2 , int start , int endInput ) {
268
+ int end = endInput ;
230
269
if (start >= len1 || len1 < len2 ) {
231
270
return -1 ;
232
271
} else if (end > len1 ) {
@@ -253,16 +292,47 @@ int find(VirtualFrame frame, PIBytesLike primary, PIBytesLike sub, Object starti
253
292
}
254
293
255
294
@ Specialization
256
- int find (VirtualFrame frame , PIBytesLike primary , int sub , Object starting , @ SuppressWarnings ("unused" ) Object ending ) {
295
+ int find (VirtualFrame frame , PIBytesLike primary , int sub , int starting , int ending ) {
296
+ SequenceStorage haystack = primary .getSequenceStorage ();
297
+ int len1 = haystack .length ();
298
+
299
+ int start = getNormalizeIndexNode ().execute (starting , len1 );
300
+ int end = getNormalizeIndexNode ().execute (ending , len1 );
301
+
302
+ return findElement (frame , sub , haystack , len1 , start , end );
303
+ }
304
+
305
+ @ Specialization
306
+ int find (VirtualFrame frame , PIBytesLike primary , int sub , int starting , Object ending ) {
307
+ SequenceStorage haystack = primary .getSequenceStorage ();
308
+ int len1 = haystack .length ();
309
+
310
+ int start = getNormalizeIndexNode ().execute (starting , len1 );
311
+ int end = getNormalizeIndexNode ().execute (ending , len1 );
312
+
313
+ return findElement (frame , sub , haystack , len1 , start , end );
314
+ }
315
+
316
+ @ Specialization
317
+ int find (VirtualFrame frame , PIBytesLike primary , int sub , Object starting , Object ending ) {
257
318
SequenceStorage haystack = primary .getSequenceStorage ();
258
319
int len1 = haystack .length ();
259
320
260
321
int start = getNormalizeIndexNode ().execute (starting , len1 );
322
+ int end = getNormalizeIndexNode ().execute (ending , len1 );
323
+
324
+ return findElement (frame , sub , haystack , len1 , start , end );
325
+ }
326
+
327
+ private int findElement (VirtualFrame frame , int sub , SequenceStorage haystack , int len1 , int start , int endInput ) {
328
+ int end = endInput ;
261
329
if (start >= len1 ) {
262
330
return -1 ;
331
+ } else if (end > len1 ) {
332
+ end = len1 ;
263
333
}
264
334
265
- for (int i = start ; i < len1 ; i ++) {
335
+ for (int i = start ; i < end ; i ++) {
266
336
int hb = getGetLeftItemNode ().executeInt (frame , haystack , i );
267
337
if (hb == sub ) {
268
338
return i ;
0 commit comments