Commit 2efa21c5 authored by Phillip Webb's avatar Phillip Webb

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
parent e141f778
...@@ -59,7 +59,7 @@ class WebDriverContextCustomizerFactory implements ContextCustomizerFactory { ...@@ -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 { ...@@ -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 { ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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; private static boolean isAlpha(char ch) {
} return ch >= 'a' && ch <= 'z';
return isAlpha || isNumeric || ch == '-'; }
private static boolean isNumeric(char ch) {
return ch >= '0' && ch <= '9';
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment