Skip to content

introduce explaining variable refactoring. #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions io/src/main/java/org/apache/pdfbox/io/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles.Lookup;

import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -237,15 +238,20 @@ private static Consumer<ByteBuffer> unmapper()
*/
final MethodHandle cleanMethod = lookup.findVirtual(cleanerClass, "clean",
methodType(void.class));
final MethodHandle nonNullTest = lookup
.findStatic(Objects.class, "nonNull",
methodType(boolean.class, Object.class))
.asType(methodType(boolean.class, cleanerClass));

final MethodType objectType = methodType(boolean.class, Object.class);
final MethodType cleanerType = methodType(boolean.class, cleanerClass);
final MethodHandle nonNullMethodHandle = lookup
.findStatic(Objects.class, "nonNull", objectType);
final MethodHandle nonNullTest = nonNullMethodHandle.asType(cleanerType);

final MethodHandle noop = dropArguments(
constant(Void.class, null).asType(methodType(void.class)), 0, cleanerClass);
final MethodHandle unmapper = filterReturnValue(directBufferCleanerMethod,
guardWithTest(nonNullTest, cleanMethod, noop))
.asType(methodType(void.class, ByteBuffer.class));
final MethodType voidBufferType = methodType(void.class, ByteBuffer.class);
final MethodHandle guardMethodHandle = guardWithTest(nonNullTest, cleanMethod, noop);
final MethodHandle unmapper = filterReturnValue(directBufferCleanerMethod, guardMethodHandle)
.asType(voidBufferType);

return newBufferCleaner(directBufferClass, unmapper);
}
}
Expand Down