Skip to content

Commit 27e89bb

Browse files
dreis2211snicoll
authored andcommitted
Optimize StringSequence
Closes spring-projectsgh-15473
1 parent 0741c90 commit 27e89bb

File tree

1 file changed

+13
-2
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar

1 file changed

+13
-2
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/StringSequence.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public StringSequence subSequence(int start, int end) {
6666
if (subSequenceEnd > this.end) {
6767
throw new StringIndexOutOfBoundsException(end);
6868
}
69+
if (start == 0 && subSequenceEnd == this.end) {
70+
return this;
71+
}
6972
return new StringSequence(this.source, subSequenceStart, subSequenceEnd);
7073
}
7174

@@ -100,10 +103,18 @@ public boolean startsWith(CharSequence prefix) {
100103
}
101104

102105
public boolean startsWith(CharSequence prefix, int offset) {
103-
if (length() - prefix.length() - offset < 0) {
106+
int prefixLength = prefix.length();
107+
if (length() - prefixLength - offset < 0) {
104108
return false;
105109
}
106-
return subSequence(offset, offset + prefix.length()).equals(prefix);
110+
int prefixOffset = 0;
111+
int sourceOffset = offset;
112+
while (prefixLength-- != 0) {
113+
if (charAt(sourceOffset++) != prefix.charAt(prefixOffset++)) {
114+
return false;
115+
}
116+
}
117+
return true;
107118
}
108119

109120
@Override

0 commit comments

Comments
 (0)