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/incubator-pekko-http.git
The following commit(s) were added to refs/heads/main by this push:
new afe9a44f5 use ByteString.toArrayUnsafe where it is safe to do so and
improves performance (#424)
afe9a44f5 is described below
commit afe9a44f5a8bbd28a8fe53418d6b00fa3387c98c
Author: PJ Fanning <[email protected]>
AuthorDate: Tue Jan 30 14:04:52 2024 +0100
use ByteString.toArrayUnsafe where it is safe to do so and improves
performance (#424)
---
.../pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala | 2 +-
.../org/apache/pekko/http/scaladsl/coding/DeflateCompressor.scala | 2 +-
.../scala/org/apache/pekko/http/scaladsl/coding/GzipCompressor.scala | 4 ++--
.../apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala
index 422edd5ad..f3b3dc5a3 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala
@@ -28,7 +28,7 @@ private[http2] object ByteStringInputStream {
bs match {
case cs: ByteString1C =>
// TODO optimise, ByteString needs to expose InputStream (esp if array
backed, nice!)
- new ByteArrayInputStream(cs.toArray)
+ new ByteArrayInputStream(cs.toArrayUnsafe())
case _ =>
// NOTE: We actually measured recently, and compact + use array was
pretty good usually
apply(bs.compact)
diff --git
a/http/src/main/scala/org/apache/pekko/http/scaladsl/coding/DeflateCompressor.scala
b/http/src/main/scala/org/apache/pekko/http/scaladsl/coding/DeflateCompressor.scala
index dbe9aec19..d1abe53f8 100644
---
a/http/src/main/scala/org/apache/pekko/http/scaladsl/coding/DeflateCompressor.scala
+++
b/http/src/main/scala/org/apache/pekko/http/scaladsl/coding/DeflateCompressor.scala
@@ -51,7 +51,7 @@ class DeflateCompressor private[coding] (compressionLevel:
Int) extends Compress
protected def compressWithBuffer(input: ByteString, buffer: Array[Byte]):
ByteString = {
require(deflater.needsInput())
- deflater.setInput(input.toArray)
+ deflater.setInput(input.toArrayUnsafe())
drainDeflater(deflater, buffer)
}
protected def flushWithBuffer(buffer: Array[Byte]): ByteString = {
diff --git
a/http/src/main/scala/org/apache/pekko/http/scaladsl/coding/GzipCompressor.scala
b/http/src/main/scala/org/apache/pekko/http/scaladsl/coding/GzipCompressor.scala
index 352f3a39f..a10156556 100644
---
a/http/src/main/scala/org/apache/pekko/http/scaladsl/coding/GzipCompressor.scala
+++
b/http/src/main/scala/org/apache/pekko/http/scaladsl/coding/GzipCompressor.scala
@@ -41,7 +41,7 @@ private[coding] class GzipCompressor(compressionLevel: Int)
extends DeflateCompr
header() ++ super.finishWithBuffer(buffer) ++ trailer()
private def updateCrc(input: ByteString): Unit = {
- checkSum.update(input.toArray)
+ checkSum.update(input.toArrayUnsafe())
bytesRead += input.length
}
private def header(): ByteString =
@@ -117,7 +117,7 @@ private[coding] class GzipDecompressor(
}
private def crc16(data: ByteString) = {
val crc = new CRC32
- crc.update(data.toArray)
+ crc.update(data.toArrayUnsafe())
crc.getValue.toInt & 0xFFFF
}
}
diff --git
a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala
b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala
index 3f4fbe32c..8134e97fe 100644
---
a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala
+++
b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala
@@ -58,7 +58,7 @@ trait Http2FrameHpackSupport extends Http2FrameProbeDelegator
with Http2FrameSen
val decoder = new Decoder(Http2Protocol.InitialMaxHeaderListSize,
Http2Protocol.InitialMaxHeaderTableSize)
def decodeHeaders(bytes: ByteString): Seq[(String, String)] = {
- val bis = new ByteArrayInputStream(bytes.toArray)
+ val bis = new ByteArrayInputStream(bytes.toArrayUnsafe())
val hs = new VectorBuilder[(String, String)]()
decoder.decode(bis,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]