mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8288011: StringConcatFactory: Split application of stringifiers
Reviewed-by: jvernee, mchung
This commit is contained in:
parent
46d5b682db
commit
5cdb4b1960
1 changed files with 34 additions and 16 deletions
|
@ -480,26 +480,38 @@ public final class StringConcatFactory {
|
|||
// The filtered argument type list is used all over in the combinators below.
|
||||
|
||||
Class<?>[] ptypes = mt.erase().parameterArray();
|
||||
MethodHandle[] filters = null;
|
||||
MethodHandle[] objFilters = null;
|
||||
MethodHandle[] floatFilters = null;
|
||||
MethodHandle[] doubleFilters = null;
|
||||
for (int i = 0; i < ptypes.length; i++) {
|
||||
Class<?> cl = ptypes[i];
|
||||
MethodHandle filter = null;
|
||||
// Use int as the logical type for subword integral types
|
||||
// (byte and short). char and boolean require special
|
||||
// handling so don't change the logical type of those
|
||||
if (cl == byte.class || cl == short.class) {
|
||||
// use int for subword integral types; still need special mixers
|
||||
// and prependers for char, boolean
|
||||
ptypes[i] = int.class;
|
||||
} else if (cl == Object.class) {
|
||||
filter = objectStringifier();
|
||||
} else if (cl == float.class) {
|
||||
filter = floatStringifier();
|
||||
} else if (cl == double.class) {
|
||||
filter = doubleStringifier();
|
||||
}
|
||||
if (filter != null) {
|
||||
if (filters == null) {
|
||||
filters = new MethodHandle[ptypes.length];
|
||||
// Object, float and double will be eagerly transformed
|
||||
// into a (non-null) String as a first step after invocation.
|
||||
// Set up to use String as the logical type for such arguments
|
||||
// internally.
|
||||
else if (cl == Object.class) {
|
||||
if (objFilters == null) {
|
||||
objFilters = new MethodHandle[ptypes.length];
|
||||
}
|
||||
filters[i] = filter;
|
||||
objFilters[i] = objectStringifier();
|
||||
ptypes[i] = String.class;
|
||||
} else if (cl == float.class) {
|
||||
if (floatFilters == null) {
|
||||
floatFilters = new MethodHandle[ptypes.length];
|
||||
}
|
||||
floatFilters[i] = floatStringifier();
|
||||
ptypes[i] = String.class;
|
||||
} else if (cl == double.class) {
|
||||
if (doubleFilters == null) {
|
||||
doubleFilters = new MethodHandle[ptypes.length];
|
||||
}
|
||||
doubleFilters[i] = doubleStringifier();
|
||||
ptypes[i] = String.class;
|
||||
}
|
||||
}
|
||||
|
@ -567,8 +579,14 @@ public final class StringConcatFactory {
|
|||
// The method handle shape here is (<args>).
|
||||
|
||||
// Apply filters, converting the arguments:
|
||||
if (filters != null) {
|
||||
mh = MethodHandles.filterArguments(mh, 0, filters);
|
||||
if (objFilters != null) {
|
||||
mh = MethodHandles.filterArguments(mh, 0, objFilters);
|
||||
}
|
||||
if (floatFilters != null) {
|
||||
mh = MethodHandles.filterArguments(mh, 0, floatFilters);
|
||||
}
|
||||
if (doubleFilters != null) {
|
||||
mh = MethodHandles.filterArguments(mh, 0, doubleFilters);
|
||||
}
|
||||
|
||||
return mh;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue