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) { if (obj == this) {
return true; return true;
} }
if (obj == null || !obj.getClass().equals(getClass())) { if (obj == null || obj.getClass() != getClass()) {
return false; return false;
} }
return true; return true;

@ -74,7 +74,7 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
@Override @Override
public boolean equals(Object obj) { 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) { if (this == obj) {
return true; return true;
} }
if (obj.getClass().equals(AsciiBytes.class)) { if (obj.getClass() == AsciiBytes.class) {
AsciiBytes other = (AsciiBytes) obj; AsciiBytes other = (AsciiBytes) obj;
if (this.length == other.length) { if (this.length == other.length) {
for (int i = 0; i < this.length; i++) { for (int i = 0; i < this.length; i++) {

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