From 0c2b761cfb3b61cd0536d774fe57bc528e4ff3a5 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 25 Nov 2020 10:31:58 +0100 Subject: [PATCH] OpenSsl.memoryAddress(...) should use internalNioBuffer(...) if it can't access the memoryAddress (#10818) Motivation: We can make use of internalNioBuffer(...) if we cant access the memoryAddress. This at least will reduce the object creations. Modifications: Use internalNioBuffer(...) and so reduce the GC Result: Less object creation if we can't access the memory address. --- handler/src/main/java/io/netty/handler/ssl/OpenSsl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java b/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java index 7869cb7791..1d934c11b2 100644 --- a/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java +++ b/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java @@ -555,7 +555,9 @@ public final class OpenSsl { static long memoryAddress(ByteBuf buf) { assert buf.isDirect(); - return buf.hasMemoryAddress() ? buf.memoryAddress() : Buffer.address(buf.nioBuffer()); + return buf.hasMemoryAddress() ? buf.memoryAddress() : + // Use internalNioBuffer to reduce object creation. + Buffer.address(buf.internalNioBuffer(0, buf.readableBytes())); } private OpenSsl() { }