Skip to content

Commit

Permalink
use toArrayUnsafe to avoid copying the array
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed May 16, 2024
1 parent f119ed1 commit 68a9495
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ trait AvroSupport {
val schema = AvroSchema[A]

Try {
val bytes = bs.toArray
val bytes = bs.toArrayUnsafe
if (bytes.length == 0) throw Unmarshaller.NoContentException
AvroInputStream.json[A].from(bytes).build(schema).iterator.next()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ trait JacksonSupport {
objectMapper: ObjectMapper with ClassTagExtensions = defaultObjectMapper
): Unmarshaller[ByteString, A] =
Unmarshaller { _ => bs =>
Future.fromTry(Try(objectMapper.readValue[A](bs.toArray)))
Future.fromTry(Try(objectMapper.readValue[A](bs.toArrayUnsafe)))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ trait JsoniterScalaSupport {
codec: JsonValueCodec[A],
config: ReaderConfig = defaultReaderConfig
): Unmarshaller[ByteString, A] =
Unmarshaller(_ => bs => Future.fromTry(Try(readFromArray(bs.toArray, config))))
Unmarshaller(_ => bs => Future.fromTry(Try(readFromArray(bs.toArrayUnsafe, config))))

/**
* HTTP entity => `Source[A, _]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ trait NinnySupport {
*/
implicit def fromByteStringUnmarshaller[A: FromJson]: Unmarshaller[ByteString, A] =
Unmarshaller(_ =>
bs => Future.fromTry(Json.parse(new String(bs.toArray, StandardCharsets.UTF_8)).to[A])
bs => Future.fromTry(Json.parse(new String(bs.toArrayUnsafe, StandardCharsets.UTF_8)).to[A])
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ trait PlayJsonSupport {
* unmarshaller for any `A` value
*/
implicit def fromByteStringUnmarshaller[A: Reads]: Unmarshaller[ByteString, A] =
Unmarshaller(_ => bs => Future.fromTry(Try(Json.parse(bs.toArray).as[A])))
Unmarshaller(_ => bs => Future.fromTry(Try(Json.parse(bs.toArrayUnsafe).as[A])))

/**
* HTTP entity => `Source[A, _]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ trait UpickleCustomizationSupport {
* unmarshaller for any `A` value
*/
implicit def fromByteStringUnmarshaller[A: api.Reader]: Unmarshaller[ByteString, A] =
Unmarshaller(_ => bs => Future.fromTry(Try(api.read(bs.toArray))))
Unmarshaller(_ => bs => Future.fromTry(Try(api.read(bs.toArrayUnsafe))))

/**
* HTTP entity => `A`
Expand Down

0 comments on commit 68a9495

Please sign in to comment.