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

fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-connectors.git


The following commit(s) were added to refs/heads/main by this push:
     new 473c5e1cb s3: avoid array copies when dealing with ByteStrings (#658)
473c5e1cb is described below

commit 473c5e1cb7734805906affae9bf0ef460cea5d7c
Author: PJ Fanning <[email protected]>
AuthorDate: Tue May 21 10:46:17 2024 +0100

    s3: avoid array copies when dealing with ByteStrings (#658)
    
    * s3: avoid array copies when dealing with ByteStrings
    
    * remove code that gets bytes directly from ByteString
---
 .../org/apache/pekko/stream/connectors/s3/impl/DiskBuffer.scala      | 2 +-
 .../org/apache/pekko/stream/connectors/s3/impl/auth/Signer.scala     | 2 +-
 .../org/apache/pekko/stream/connectors/s3/impl/auth/package.scala    | 5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git 
a/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/DiskBuffer.scala 
b/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/DiskBuffer.scala
index 3c4ec2d7e..068a88eed 100644
--- 
a/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/DiskBuffer.scala
+++ 
b/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/DiskBuffer.scala
@@ -78,7 +78,7 @@ import pekko.annotation.InternalApi
           throw new BufferOverflowException()
         }
 
-        pathOut.write(elem.toArray)
+        pathOut.write(elem.toArrayUnsafe())
         pull(in)
       }
 
diff --git 
a/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/auth/Signer.scala
 
b/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/auth/Signer.scala
index 89f21e820..fd7404659 100644
--- 
a/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/auth/Signer.scala
+++ 
b/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/auth/Signer.scala
@@ -32,7 +32,7 @@ import pekko.stream.scaladsl.Source
       signAnonymousRequests: Boolean): Source[HttpRequest, NotUsed] =
     if (!signAnonymousRequests && key.anonymous) Source.single(request)
     else {
-      val hashedBody = request.entity.dataBytes.via(digest()).map(hash => 
encodeHex(hash.toArray))
+      val hashedBody = request.entity.dataBytes.via(digest()).map(hash => 
encodeHex(hash))
 
       hashedBody
         .map { hb =>
diff --git 
a/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/auth/package.scala
 
b/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/auth/package.scala
index 91c845c76..33f4b1f69 100644
--- 
a/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/auth/package.scala
+++ 
b/s3/src/main/scala/org/apache/pekko/stream/connectors/s3/impl/auth/package.scala
@@ -36,7 +36,8 @@ package object auth {
     new String(out)
   }
 
-  @InternalApi private[impl] def encodeHex(bytes: ByteString): String = 
encodeHex(bytes.toArray)
+  @InternalApi private[impl] def encodeHex(bytes: ByteString): String =
+    encodeHex(bytes.toArrayUnsafe())
 
   @InternalApi private[impl] def digest(algorithm: String = "SHA-256"): 
Flow[ByteString, ByteString, NotUsed] =
     Flow[ByteString]
@@ -45,5 +46,5 @@ package object auth {
           digest.update(bytes.asByteBuffer)
           digest
       }
-      .map(d => ByteString(d.digest()))
+      .map(d => ByteString.fromArrayUnsafe(d.digest()))
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to