mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8318457: Use prefix-less prepend methods directly to reduce branches in String concat expressions
Reviewed-by: jlaskey, liach
This commit is contained in:
parent
71c99a0e59
commit
fe52917054
3 changed files with 35 additions and 30 deletions
|
@ -700,19 +700,12 @@ public final class StringConcatFactory {
|
|||
// Simple prependers, single argument. May be used directly or as a
|
||||
// building block for complex prepender combinators.
|
||||
private static MethodHandle prepender(String prefix, Class<?> cl) {
|
||||
MethodHandle prepend;
|
||||
int idx = classIndex(cl);
|
||||
if (prefix == null) {
|
||||
prepend = NULL_PREPENDERS[idx];
|
||||
if (prepend == null) {
|
||||
NULL_PREPENDERS[idx] = prepend = MethodHandles.insertArguments(
|
||||
prepender(cl), 3, (String)null);
|
||||
}
|
||||
if (prefix == null || prefix.isEmpty()) {
|
||||
return noPrefixPrepender(cl);
|
||||
} else {
|
||||
prepend = MethodHandles.insertArguments(
|
||||
return MethodHandles.insertArguments(
|
||||
prepender(cl), 3, prefix);
|
||||
}
|
||||
return prepend;
|
||||
}
|
||||
|
||||
private static MethodHandle prepender(Class<?> cl) {
|
||||
|
@ -729,6 +722,20 @@ public final class StringConcatFactory {
|
|||
return prepend;
|
||||
}
|
||||
|
||||
private static MethodHandle noPrefixPrepender(Class<?> cl) {
|
||||
int idx = classIndex(cl);
|
||||
MethodHandle prepend = NO_PREFIX_PREPENDERS[idx];
|
||||
if (prepend == null) {
|
||||
if (idx == STRING_CONCAT_ITEM) {
|
||||
cl = FormatConcatItem.class;
|
||||
}
|
||||
NO_PREFIX_PREPENDERS[idx] = prepend = JLA.stringConcatHelper("prepend",
|
||||
methodType(long.class, long.class, byte[].class,
|
||||
Wrapper.asPrimitiveType(cl))).rebind();
|
||||
}
|
||||
return prepend;
|
||||
}
|
||||
|
||||
private static final int INT_IDX = 0,
|
||||
CHAR_IDX = 1,
|
||||
LONG_IDX = 2,
|
||||
|
@ -995,7 +1002,7 @@ public final class StringConcatFactory {
|
|||
}
|
||||
}
|
||||
|
||||
private static final @Stable MethodHandle[] NULL_PREPENDERS = new MethodHandle[TYPE_COUNT];
|
||||
private static final @Stable MethodHandle[] NO_PREFIX_PREPENDERS = new MethodHandle[TYPE_COUNT];
|
||||
private static final @Stable MethodHandle[] PREPENDERS = new MethodHandle[TYPE_COUNT];
|
||||
private static final @Stable MethodHandle[] MIXERS = new MethodHandle[TYPE_COUNT];
|
||||
private static final long INITIAL_CODER = JLA.stringConcatInitialCoder();
|
||||
|
@ -1117,7 +1124,7 @@ public final class StringConcatFactory {
|
|||
|
||||
Class<?> ttype = ttypes[pos];
|
||||
// (long,byte[],ttype) -> long
|
||||
MethodHandle prepender = prepender(fragment.isEmpty() ? null : fragment, ttype);
|
||||
MethodHandle prepender = prepender(fragment, ttype);
|
||||
// (byte[],long,ttypes...) -> String (unchanged)
|
||||
mh = MethodHandles.filterArgumentsWithCombiner(mh, 1, prepender,1, 0, 2 + pos);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue