int (@NotNull CharSequence text, char @Nullable [] textArray, int _start, int _end) { if (_start > _end) { throw new AssertionError("start > end, " + _start + ">" + _end); } final int textLength = text.length(); if (_end > textLength) { throw new AssertionError("end > length, " + _end + ">" + textLength); } if (myForwardDirection) { if (myPatternLength == 1) { // optimization return Strings.indexOf(text, myPatternArray[0], _start, _end, myCaseSensitive); } int start = _start; int end = _end - myPatternLength; while (start <= end) { int i = myPatternLength - 1; char lastChar = normalizedCharAt(text, textArray, start + i); if (isSameChar(myPatternArray[i], lastChar)) { i--; while (i >= 0) { char c = textArray != null ? textArray[start + i] : text.charAt(start + i); if (!isSameChar(myPatternArray[i], c)) break; i--; } if (i < 0) { return start; } } int step = lastChar < 128 ? mySearchTable[lastChar] : 1; if (step <= 0) { int index; for (index = myPatternLength - 2; index >= 0; index--) { if (myPatternArray[index] == lastChar) break; } step = myPatternLength - index - 1; mySearchTable[lastChar] = step; } start += step; } } else { int start = 1; while (start <= _end - myPatternLength + 1) { int i = myPatternLength - 1; char lastChar = normalizedCharAt(text, textArray, _end - (start + i)); if (isSameChar(myPatternArray[myPatternLength - 1 - i], lastChar)) { i--; while (i >= 0) { char c = textArray != null ? textArray[_end - (start + i)] : text.charAt(_end - (start + i)); if (!isSameChar(myPatternArray[myPatternLength - 1 - i], c)) break; i--; } if (i < 0) return _end - start - myPatternLength + 1; } int step = lastChar < 128 ? mySearchTable[lastChar] : 1; if (step <= 0) { int index; for (index = myPatternLength - 2; index >= 0; index--) { if (myPatternArray[myPatternLength - 1 - index] == lastChar) break; } step = myPatternLength - index - 1; mySearchTable[lastChar] = step; } start += step; } } return -1; }