pjfanning commented on code in PR #539:
URL: https://github.com/apache/pekko-http/pull/539#discussion_r1576837896
##########
http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala:
##########
@@ -24,13 +27,29 @@ import pekko.util.ByteString.ByteString1C
@InternalApi
private[http2] object ByteStringInputStream {
- def apply(bs: ByteString): InputStream =
- bs match {
- case cs: ByteString1C =>
- // TODO optimise, ByteString needs to expose InputStream (esp if array
backed, nice!)
- new ByteArrayInputStream(cs.toArrayUnsafe())
- case _ =>
- // NOTE: We actually measured recently, and compact + use array was
pretty good usually
- apply(bs.compact)
+ private lazy val byteStringInputStreamMethodTypeOpt = Try {
+ val lookup = MethodHandles.publicLookup()
+ val inputStreamMethodType = MethodType.methodType(classOf[InputStream])
+ lookup.findVirtual(classOf[ByteString], "asInputStream",
inputStreamMethodType)
+ }.toOption
+
+ def apply(bs: ByteString): InputStream = bs match {
+ case cs: ByteString1C =>
+ new ByteArrayInputStream(cs.toArrayUnsafe())
Review Comment:
https://github.com/pjfanning/pekko-test/tree/instanceof -- this branch is
slower than the main branch - the instanceof is slower than the pattern matching
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]