Skip to content

Commit 45d150a

Browse files
committed
More efficient serialization for OpenRTBWriting.circe, OpenRTBWriting.circeJsoniter, TwitterAPIWriting.circe and TwitterAPIWriting.circeJsoniter benchmarks
1 parent c7e6a2e commit 45d150a

File tree

1 file changed

+5
-3
lines changed
  • jsoniter-scala-benchmark/shared/src/main/scala/io/circe

1 file changed

+5
-3
lines changed

jsoniter-scala-benchmark/shared/src/main/scala/io/circe/Util.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object Util {
2626
}
2727

2828
def onObject(value: JsonObject): Json = new JObject(JsonObject.fromLinkedHashMap {
29-
val map = new util.LinkedHashMap[String, Json]
29+
val map = new util.LinkedHashMap[String, Json](value.size << 1, 0.5f)
3030
value.toIterable.foreach { case (k, v) =>
3131
lazy val folded = v.foldWith(this)
3232
if (!{
@@ -41,8 +41,10 @@ object Util {
4141
def deepDropEmptyValues(json: Json): Json = json.foldWith(dropEmptyValueFolder)
4242

4343
def toJObject(fields: (String, Json)*): Json = new JObject(JsonObject.fromLinkedHashMap {
44-
val map = new util.LinkedHashMap[String, Json]
45-
fields.foreach { case (k, v) =>
44+
val map = new util.LinkedHashMap[String, Json](fields.size << 1, 0.5f)
45+
val it = fields.iterator
46+
while (it.hasNext) {
47+
val (k, v) = it.next()
4648
if (!(v.isNull || v.isArray && v.asInstanceOf[JArray].value.isEmpty)) map.put(k, v)
4749
}
4850
map

0 commit comments

Comments
 (0)