From 8e894e2e49eacb298c18e1b082a9fa5ec4c1e2e3 Mon Sep 17 00:00:00 2001 From: kares Date: Mon, 21 Dec 2015 17:26:14 +0100 Subject: [PATCH] SSLSocket#sysread do not copy bytes from buffer - instead re-use the backing array --- src/main/java/org/jruby/ext/openssl/SSLSocket.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jruby/ext/openssl/SSLSocket.java b/src/main/java/org/jruby/ext/openssl/SSLSocket.java index c4fa32b3..2346f975 100644 --- a/src/main/java/org/jruby/ext/openssl/SSLSocket.java +++ b/src/main/java/org/jruby/ext/openssl/SSLSocket.java @@ -757,10 +757,9 @@ private IRubyObject sysreadImpl(final ThreadContext context, if ( ex instanceof IRubyObject ) return (IRubyObject) ex; // :wait_readable } } - byte[] bytesRead = new byte[read]; - dst.position(dst.position() - read); - dst.get(bytesRead); - buffStr.setValue(new ByteList(bytesRead, false)); + final byte[] bytesRead = dst.array(); + final int offset = dst.position() - read; + buffStr.setValue(new ByteList(bytesRead, offset, read, false)); return buffStr; } catch (IOException ioe) {