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
pull/11365/merge
Phillip Webb 7 years ago
parent e141f77801
commit 2efa21c570

@ -59,7 +59,7 @@ class WebDriverContextCustomizerFactory implements ContextCustomizerFactory {
if (obj == this) {
return true;
}
if (obj == null || !obj.getClass().equals(getClass())) {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
return true;

@ -74,7 +74,7 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
@Override
public boolean equals(Object obj) {
return (obj != null && obj.getClass().equals(getClass()));
return (obj != null && obj.getClass() == getClass());
}
/**

@ -211,7 +211,7 @@ final class AsciiBytes {
if (this == obj) {
return true;
}
if (obj.getClass().equals(AsciiBytes.class)) {
if (obj.getClass() == AsciiBytes.class) {
AsciiBytes other = (AsciiBytes) obj;
if (this.length == other.length) {
for (int i = 0; i < this.length; i++) {

@ -355,7 +355,7 @@ public final class ConfigurationPropertyName
if (obj == this) {
return true;
}
if (obj == null || !obj.getClass().equals(getClass())) {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
ConfigurationPropertyName other = (ConfigurationPropertyName) obj;
@ -410,8 +410,11 @@ public final class ConfigurationPropertyName
private static boolean isIndexed(CharSequence element) {
int length = element.length();
return length > 2 && element.charAt(0) == '['
&& element.charAt(length - 1) == ']';
return charAt(element, 0) == '[' && charAt(element, length - 1) == ']';
}
private static char charAt(CharSequence element, int index) {
return (index < element.length() ? element.charAt(index) : 0);
}
/**
@ -496,7 +499,7 @@ public final class ConfigurationPropertyName
if (name.length() == 0) {
return EMPTY;
}
List<CharSequence> elements = new ArrayList<>(10);
List<CharSequence> elements = new ArrayList<>();
process(name, separator, (elementValue, start, end, indexed) -> {
elementValue = elementValueProcessor.apply(elementValue);
if (!isIndexed(elementValue)) {
@ -656,10 +659,16 @@ public final class ConfigurationPropertyName
}
public static boolean isValidElement(CharSequence elementValue) {
return getInvalidChars(elementValue).isEmpty();
for (int i = 0; i < elementValue.length(); i++) {
char ch = elementValue.charAt(i);
if (!isValidChar(ch, i)) {
return false;
}
}
return true;
}
private static List<Character> getInvalidChars(CharSequence elementValue) {
public static List<Character> getInvalidChars(CharSequence elementValue) {
List<Character> chars = new ArrayList<>();
for (int i = 0; i < elementValue.length(); i++) {
char ch = elementValue.charAt(i);
@ -671,12 +680,15 @@ public final class ConfigurationPropertyName
}
public static boolean isValidChar(char ch, int index) {
boolean isAlpha = ch >= 'a' && ch <= 'z';
boolean isNumeric = ch >= '0' && ch <= '9';
if (index == 0) {
return isAlpha;
}
return isAlpha || isNumeric || ch == '-';
return isAlpha(ch) || (index != 0 && (isNumeric(ch) || ch == '-'));
}
private static boolean isAlpha(char ch) {
return ch >= 'a' && ch <= 'z';
}
private static boolean isNumeric(char ch) {
return ch >= '0' && ch <= '9';
}
}

Loading…
Cancel
Save