Skip to content

Commit 70ffc70

Browse files
dreis2211philwebb
authored andcommitted
Optimize StringSequence.startsWith
See gh-21259
1 parent 7634901 commit 70ffc70

File tree

1 file changed

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

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -98,15 +98,19 @@ int indexOf(String str, int fromIndex) {
9898
return this.source.indexOf(str, this.start + fromIndex) - this.start;
9999
}
100100

101-
boolean startsWith(CharSequence prefix) {
101+
boolean startsWith(String prefix) {
102102
return startsWith(prefix, 0);
103103
}
104104

105-
boolean startsWith(CharSequence prefix, int offset) {
105+
boolean startsWith(String prefix, int offset) {
106106
int prefixLength = prefix.length();
107-
if (length() - prefixLength - offset < 0) {
107+
int length = length();
108+
if (length - prefixLength - offset < 0) {
108109
return false;
109110
}
111+
if (length == this.source.length()) {
112+
return this.source.startsWith(prefix, offset);
113+
}
110114
int prefixOffset = 0;
111115
int sourceOffset = offset;
112116
while (prefixLength-- != 0) {

0 commit comments

Comments
 (0)