Skip to content

Commit 7df1e7f

Browse files
committed
More efficient serialization for ArraySeqOfBooleansWriting.sprayJson benchmark
1 parent 2f5c100 commit 7df1e7f

File tree

1 file changed

+9
-3
lines changed
  • jsoniter-scala-benchmark/shared/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/benchmark

1 file changed

+9
-3
lines changed

jsoniter-scala-benchmark/shared/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/benchmark/SprayFormats.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,15 @@ object SprayFormats extends DefaultJsonProtocol {
12721272
new RootJsonFormat[ArraySeq[T]] {
12731273
def read(json: JsValue): ArraySeq[T] = json match {
12741274
case ja: JsArray =>
1275-
val b = ArraySeq.newBuilder[T]
1276-
ja.elements.foreach(e => b.addOne(e.convertTo[T]))
1277-
b.result()
1275+
val v = ja.elements
1276+
val a = new Array[T](v.size)
1277+
v.foreach {
1278+
var i = 0
1279+
e =>
1280+
a(i) = e.convertTo[T]
1281+
i += 1
1282+
}
1283+
ArraySeq.unsafeWrapArray(a)
12781284
case _ => deserializationError(s"Expected JSON array")
12791285
}
12801286

0 commit comments

Comments
 (0)