Skip to content

Commit

Permalink
8288011: StringConcatFactory: Split application of stringifiers
Browse files Browse the repository at this point in the history
Reviewed-by: jvernee, mchung
  • Loading branch information
cl4es committed Jun 20, 2022
1 parent 46d5b68 commit 5cdb4b1
Showing 1 changed file with 33 additions and 15 deletions.
Expand Up @@ -480,26 +480,38 @@ private static MethodHandle generateMHInlineCopy(MethodType mt, String[] constan
// 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();
}
// 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];
}
objFilters[i] = objectStringifier();
ptypes[i] = String.class;
} else if (cl == float.class) {
filter = floatStringifier();
if (floatFilters == null) {
floatFilters = new MethodHandle[ptypes.length];
}
floatFilters[i] = floatStringifier();
ptypes[i] = String.class;
} else if (cl == double.class) {
filter = doubleStringifier();
}
if (filter != null) {
if (filters == null) {
filters = new MethodHandle[ptypes.length];
if (doubleFilters == null) {
doubleFilters = new MethodHandle[ptypes.length];
}
filters[i] = filter;
doubleFilters[i] = doubleStringifier();
ptypes[i] = String.class;
}
}
Expand Down Expand Up @@ -567,8 +579,14 @@ private static MethodHandle generateMHInlineCopy(MethodType mt, String[] constan
// 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;
Expand Down

1 comment on commit 5cdb4b1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.