Commit 70ffc709 authored by dreis2211's avatar dreis2211 Committed by Phillip Webb

Optimize StringSequence.startsWith

See gh-21259
parent 7634901f
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -98,15 +98,19 @@ final class StringSequence implements CharSequence {
return this.source.indexOf(str, this.start + fromIndex) - this.start;
}
boolean startsWith(CharSequence prefix) {
boolean startsWith(String prefix) {
return startsWith(prefix, 0);
}
boolean startsWith(CharSequence prefix, int offset) {
boolean startsWith(String prefix, int offset) {
int prefixLength = prefix.length();
if (length() - prefixLength - offset < 0) {
int length = length();
if (length - prefixLength - offset < 0) {
return false;
}
if (length == this.source.length()) {
return this.source.startsWith(prefix, offset);
}
int prefixOffset = 0;
int sourceOffset = offset;
while (prefixLength-- != 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment