Skip to content

Commit 2efa21c

Browse files
committed
Make hot methods in-line friendly
Refactor a few hot methods so that they are more likely to be in-lined by the JIT. Fixes gh-11409
1 parent e141f77 commit 2efa21c

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public boolean equals(Object obj) {
5959
if (obj == this) {
6060
return true;
6161
}
62-
if (obj == null || !obj.getClass().equals(getClass())) {
62+
if (obj == null || obj.getClass() != getClass()) {
6363
return false;
6464
}
6565
return true;

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public int hashCode() {
7474

7575
@Override
7676
public boolean equals(Object obj) {
77-
return (obj != null && obj.getClass().equals(getClass()));
77+
return (obj != null && obj.getClass() == getClass());
7878
}
7979

8080
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public boolean equals(Object obj) {
211211
if (this == obj) {
212212
return true;
213213
}
214-
if (obj.getClass().equals(AsciiBytes.class)) {
214+
if (obj.getClass() == AsciiBytes.class) {
215215
AsciiBytes other = (AsciiBytes) obj;
216216
if (this.length == other.length) {
217217
for (int i = 0; i < this.length; i++) {

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public boolean equals(Object obj) {
355355
if (obj == this) {
356356
return true;
357357
}
358-
if (obj == null || !obj.getClass().equals(getClass())) {
358+
if (obj == null || obj.getClass() != getClass()) {
359359
return false;
360360
}
361361
ConfigurationPropertyName other = (ConfigurationPropertyName) obj;
@@ -410,8 +410,11 @@ else if (ch1 != ch2) {
410410

411411
private static boolean isIndexed(CharSequence element) {
412412
int length = element.length();
413-
return length > 2 && element.charAt(0) == '['
414-
&& element.charAt(length - 1) == ']';
413+
return charAt(element, 0) == '[' && charAt(element, length - 1) == ']';
414+
}
415+
416+
private static char charAt(CharSequence element, int index) {
417+
return (index < element.length() ? element.charAt(index) : 0);
415418
}
416419

417420
/**
@@ -496,7 +499,7 @@ static ConfigurationPropertyName adapt(CharSequence name, char separator,
496499
if (name.length() == 0) {
497500
return EMPTY;
498501
}
499-
List<CharSequence> elements = new ArrayList<>(10);
502+
List<CharSequence> elements = new ArrayList<>();
500503
process(name, separator, (elementValue, start, end, indexed) -> {
501504
elementValue = elementValueProcessor.apply(elementValue);
502505
if (!isIndexed(elementValue)) {
@@ -656,10 +659,16 @@ public boolean isValid() {
656659
}
657660

658661
public static boolean isValidElement(CharSequence elementValue) {
659-
return getInvalidChars(elementValue).isEmpty();
662+
for (int i = 0; i < elementValue.length(); i++) {
663+
char ch = elementValue.charAt(i);
664+
if (!isValidChar(ch, i)) {
665+
return false;
666+
}
667+
}
668+
return true;
660669
}
661670

662-
private static List<Character> getInvalidChars(CharSequence elementValue) {
671+
public static List<Character> getInvalidChars(CharSequence elementValue) {
663672
List<Character> chars = new ArrayList<>();
664673
for (int i = 0; i < elementValue.length(); i++) {
665674
char ch = elementValue.charAt(i);
@@ -671,12 +680,15 @@ private static List<Character> getInvalidChars(CharSequence elementValue) {
671680
}
672681

673682
public static boolean isValidChar(char ch, int index) {
674-
boolean isAlpha = ch >= 'a' && ch <= 'z';
675-
boolean isNumeric = ch >= '0' && ch <= '9';
676-
if (index == 0) {
677-
return isAlpha;
678-
}
679-
return isAlpha || isNumeric || ch == '-';
683+
return isAlpha(ch) || (index != 0 && (isNumeric(ch) || ch == '-'));
684+
}
685+
686+
private static boolean isAlpha(char ch) {
687+
return ch >= 'a' && ch <= 'z';
688+
}
689+
690+
private static boolean isNumeric(char ch) {
691+
return ch >= '0' && ch <= '9';
680692
}
681693

682694
}

0 commit comments

Comments
 (0)