8262994: Refactor String.split to help method inlining

Reviewed-by: plevart
This commit is contained in:
Christian Wimmer 2023-01-30 23:33:11 +00:00 committed by Peter Levart
parent 2d7690b2e5
commit 622b6594d1

View file

@ -3129,6 +3129,17 @@ public final class String
(ch < Character.MIN_HIGH_SURROGATE || (ch < Character.MIN_HIGH_SURROGATE ||
ch > Character.MAX_LOW_SURROGATE)) ch > Character.MAX_LOW_SURROGATE))
{ {
// All the checks above can potentially be constant folded by
// a JIT/AOT compiler when the regex is a constant string.
// That requires method inlining of the checks, which is only
// possible when the actual split logic is in a separate method
// because the large split loop can usually not be inlined.
return split(ch, limit);
}
return Pattern.compile(regex).split(this, limit);
}
private String[] split(char ch, int limit) {
int off = 0; int off = 0;
int next = 0; int next = 0;
boolean limited = limit > 0; boolean limited = limit > 0;
@ -3163,8 +3174,6 @@ public final class String
String[] result = new String[resultSize]; String[] result = new String[resultSize];
return list.subList(0, resultSize).toArray(result); return list.subList(0, resultSize).toArray(result);
} }
return Pattern.compile(regex).split(this, limit);
}
/** /**
* Splits this string around matches of the given <a * Splits this string around matches of the given <a