From 6d47764b9943462cb634899cd7bf805ecd2a3af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20M=C3=A9lois?= Date: Fri, 11 Oct 2024 12:52:49 +0200 Subject: [PATCH] Optimise conversion from Blob to Stream Motivated by https://github.com/http4s/http4s/issues/7539 --- .../http4s-kernel/src/smithy4s/http4s/kernel/package.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/http4s-kernel/src/smithy4s/http4s/kernel/package.scala b/modules/http4s-kernel/src/smithy4s/http4s/kernel/package.scala index 690bf24ad..dee0c0424 100644 --- a/modules/http4s-kernel/src/smithy4s/http4s/kernel/package.scala +++ b/modules/http4s-kernel/src/smithy4s/http4s/kernel/package.scala @@ -204,6 +204,8 @@ package object kernel { private def toStream[F[_]]( blob: Blob - ): Stream[F, Byte] = Stream.chunk(Chunk.array(blob.toArray)) + ): Stream[F, Byte] = + // Optimisation motivated by https://github.com/http4s/http4s/issues/7539 + if (blob.isEmpty) Stream.empty else Stream.chunk(Chunk.array(blob.toArray)) }