This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new f3ebf6b  Avoid copying useless bytes using asSlice
f3ebf6b is described below

commit f3ebf6beef5520780d5be54e4ebd24a0db3bfea2
Author: remm <r...@apache.org>
AuthorDate: Mon Nov 8 16:06:16 2021 +0100

    Avoid copying useless bytes using asSlice
---
 .../org/apache/tomcat/util/net/openssl/panama/OpenSSLEngine.java  | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/modules/openssl-java17/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLEngine.java
 
b/modules/openssl-java17/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLEngine.java
index 68ffe30..d8d827f 100644
--- 
a/modules/openssl-java17/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLEngine.java
+++ 
b/modules/openssl-java17/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLEngine.java
@@ -401,8 +401,8 @@ public final class OpenSSLEngine extends SSLEngine 
implements SSLUtil.ProtocolIn
                 MemorySegment bufSegment = 
allocator.allocateArray(CLinker.C_CHAR, len);
                 final int sslRead = SSL_read(ssl, bufSegment, len);
                 if (sslRead > 0) {
-                    byte[] buf = bufSegment.toByteArray();
-                    dst.put(buf, 0, sslRead);
+                    
MemorySegment.ofByteBuffer(dst).copyFrom(bufSegment.asSlice(0, sslRead));
+                    dst.position(dst.position() + sslRead);
                     return sslRead;
                 } else {
                     checkLastError();
@@ -419,8 +419,8 @@ public final class OpenSSLEngine extends SSLEngine 
implements SSLUtil.ProtocolIn
      */
     private int readEncryptedData(final MemoryAddress networkBIO, final 
ByteBuffer dst, final int pending) throws SSLException {
         clearLastError();
+        final int pos = dst.position();
         if (dst.isDirect()) {
-            final int pos = dst.position();
             final int bioRead = BIO_read(networkBIO, 
MemorySegment.ofByteBuffer(dst), pending);
             if (bioRead > 0) {
                 dst.position(pos + bioRead);
@@ -436,7 +436,7 @@ public final class OpenSSLEngine extends SSLEngine 
implements SSLUtil.ProtocolIn
                 if (bioRead > 0) {
                     buf.limit(bioRead);
                     int oldLimit = dst.limit();
-                    dst.limit(dst.position() + bioRead);
+                    dst.limit(pos + bioRead);
                     dst.put(buf);
                     dst.limit(oldLimit);
                     return bioRead;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to