This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-http.git
The following commit(s) were added to refs/heads/main by this push:
new cd3584989 use ByteString toArrayUnsafe in new deflater code (#1135)
cd3584989 is described below
commit cd35849891385b64b444923a5436e5487ab03229
Author: PJ Fanning <[email protected]>
AuthorDate: Wed Jul 8 21:25:29 2026 +0100
use ByteString toArrayUnsafe in new deflater code (#1135)
* use ByteString toArrayUnsafe
* try fromArrayUnsafe in more places
* Update HPackEncodingSupport.scala
* revert unrelated changes
* Update HPackEncodingSupport.scala
---
.../apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala
index eb71b21d0..96d2c282d 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala
@@ -194,8 +194,8 @@ private[http] object PerMessageDeflate {
private def inflate(data: ByteString, appendTail: Boolean): ByteString = {
try {
val input = if (appendTail) data ++ EmptyStoredBlock else data
- inflater.setInput(input.toArray)
- val output = new ByteArrayOutputStream()
+ inflater.setInput(input.toArrayUnsafe())
+ val output = new ByteArrayOutputStream(1024)
val buffer = new Array[Byte](1024)
var count = inflater.inflate(buffer)
while (count > 0) {
@@ -205,7 +205,7 @@ private[http] object PerMessageDeflate {
output.write(buffer, 0, count)
count = inflater.inflate(buffer)
}
- ByteString.fromArray(output.toByteArray)
+ ByteString.fromArrayUnsafe(output.toByteArray)
} catch {
case ex: DataFormatException =>
throw new ProtocolException(s"Invalid WebSocket compressed message:
${ex.getMessage}")
@@ -275,15 +275,15 @@ private[http] object PerMessageDeflate {
}
private def deflate(data: ByteString, removeTail: Boolean): ByteString = {
- deflater.setInput(data.toArray)
- val output = new ByteArrayOutputStream()
+ deflater.setInput(data.toArrayUnsafe())
+ val output = new ByteArrayOutputStream(1024)
val buffer = new Array[Byte](1024)
var count = deflater.deflate(buffer, 0, buffer.length,
Deflater.SYNC_FLUSH)
while (count > 0) {
output.write(buffer, 0, count)
count = deflater.deflate(buffer, 0, buffer.length, Deflater.SYNC_FLUSH)
}
- val bytes = ByteString.fromArray(output.toByteArray)
+ val bytes = ByteString.fromArrayUnsafe(output.toByteArray)
if (removeTail && bytes.endsWith(EmptyStoredBlock))
bytes.dropRight(EmptyStoredBlock.length) else bytes
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]