From 2ad2da5818a9934834d9b1702428c2d4509a4af1 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 3 Oct 2025 15:50:56 +0100 Subject: [PATCH 1/2] safe to create ByteString from array with no-copy --- .../apache/pekko/http/impl/engine/ws/FrameEventRenderer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/FrameEventRenderer.scala b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/FrameEventRenderer.scala index d445ae80a..603be504e 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/FrameEventRenderer.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/FrameEventRenderer.scala @@ -129,6 +129,6 @@ private[http] final class FrameEventRenderer extends GraphStage[FlowShape[FrameE data(maskOffset + 3) = ((mask & 0x000000FF) >> 0).toByte } - ByteString(data) + ByteString.fromArrayUnsafe(data) } } From 092a279fd4a6773a8b8240b0fdb343a26cb185e4 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 3 Oct 2025 16:39:42 +0100 Subject: [PATCH 2/2] another place where we know that the array is private in scope --- .../scaladsl/marshalling/PredefinedToEntityMarshallers.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http/src/main/scala/org/apache/pekko/http/scaladsl/marshalling/PredefinedToEntityMarshallers.scala b/http/src/main/scala/org/apache/pekko/http/scaladsl/marshalling/PredefinedToEntityMarshallers.scala index 03d67d068..fee8181fe 100644 --- a/http/src/main/scala/org/apache/pekko/http/scaladsl/marshalling/PredefinedToEntityMarshallers.scala +++ b/http/src/main/scala/org/apache/pekko/http/scaladsl/marshalling/PredefinedToEntityMarshallers.scala @@ -47,7 +47,7 @@ trait PredefinedToEntityMarshallers extends MultipartMarshallers { val byteBuffer = contentType.charset.nioCharset.encode(charBuffer) val array = new Array[Byte](byteBuffer.remaining()) byteBuffer.get(array) - HttpEntity(contentType, array) + HttpEntity(contentType, ByteString.fromArrayUnsafe(array)) } else HttpEntity.Empty implicit val DoneMarshaller: ToEntityMarshaller[pekko.Done] =