From fc5b655321a6879018f2ef272ce775d76ee42412 Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Sat, 17 Jun 2023 11:13:19 +0200 Subject: [PATCH 1/4] Optimize UnwrapArray parser by caching JValue ClassTag --- ast/shared/src/main/scala/jawn/ast/JValue.scala | 4 +++- ast/shared/src/main/scala/jawn/ast/JawnFacade.scala | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ast/shared/src/main/scala/jawn/ast/JValue.scala b/ast/shared/src/main/scala/jawn/ast/JValue.scala index 31354155..71bb49a8 100644 --- a/ast/shared/src/main/scala/jawn/ast/JValue.scala +++ b/ast/shared/src/main/scala/jawn/ast/JValue.scala @@ -22,8 +22,9 @@ package org.typelevel.jawn package ast -import java.lang.Double.{isInfinite, isNaN} +import java.lang.Double.{ isInfinite, isNaN } import scala.collection.mutable +import scala.reflect.ClassTag import scala.util.hashing.MurmurHash3 class WrongValueException(e: String, g: String) extends Exception(s"expected $e, got $g") @@ -81,6 +82,7 @@ sealed abstract class JValue { object JValue { implicit val facade: Facade[JValue] = JawnFacade + implicit val classTag: ClassTag[JValue] = ClassTag(classOf[JValue]) } sealed abstract class JAtom extends JValue { diff --git a/ast/shared/src/main/scala/jawn/ast/JawnFacade.scala b/ast/shared/src/main/scala/jawn/ast/JawnFacade.scala index 89309863..8f206b66 100644 --- a/ast/shared/src/main/scala/jawn/ast/JawnFacade.scala +++ b/ast/shared/src/main/scala/jawn/ast/JawnFacade.scala @@ -53,7 +53,7 @@ object JawnFacade extends Facade.NoIndexFacade[JValue] { private[this] val vs = mutable.ArrayBuffer.empty[JValue] def add(s: CharSequence): Unit = vs += JString(s.toString) def add(v: JValue): Unit = vs += v - def finish(): JValue = JArray(vs.toArray) + def finish(): JValue = JArray(vs.toArray(JValue.classTag)) def isObj: Boolean = false } From 59c20892aebd306d8936e46c59eb192f1e16f633 Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Sat, 17 Jun 2023 17:46:19 +0200 Subject: [PATCH 2/4] fmt --- ast/shared/src/main/scala/jawn/ast/JValue.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ast/shared/src/main/scala/jawn/ast/JValue.scala b/ast/shared/src/main/scala/jawn/ast/JValue.scala index 71bb49a8..68b99de0 100644 --- a/ast/shared/src/main/scala/jawn/ast/JValue.scala +++ b/ast/shared/src/main/scala/jawn/ast/JValue.scala @@ -22,7 +22,7 @@ package org.typelevel.jawn package ast -import java.lang.Double.{ isInfinite, isNaN } +import java.lang.Double.{isInfinite, isNaN} import scala.collection.mutable import scala.reflect.ClassTag import scala.util.hashing.MurmurHash3 From 30cf5141f1d26081f81d2fa32afccde8c23a67c7 Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Mon, 19 Jun 2023 08:40:03 +0200 Subject: [PATCH 3/4] make it lazy to defer reflection --- ast/shared/src/main/scala/jawn/ast/JValue.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ast/shared/src/main/scala/jawn/ast/JValue.scala b/ast/shared/src/main/scala/jawn/ast/JValue.scala index 68b99de0..ec97ce76 100644 --- a/ast/shared/src/main/scala/jawn/ast/JValue.scala +++ b/ast/shared/src/main/scala/jawn/ast/JValue.scala @@ -82,7 +82,7 @@ sealed abstract class JValue { object JValue { implicit val facade: Facade[JValue] = JawnFacade - implicit val classTag: ClassTag[JValue] = ClassTag(classOf[JValue]) + implicit lazy val classTag: ClassTag[JValue] = ClassTag(classOf[JValue]) } sealed abstract class JAtom extends JValue { From c61b9512fa66e385caeae46d335c506799daa819 Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Thu, 22 Jun 2023 10:14:13 +0200 Subject: [PATCH 4/4] make private --- ast/shared/src/main/scala/jawn/ast/JValue.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ast/shared/src/main/scala/jawn/ast/JValue.scala b/ast/shared/src/main/scala/jawn/ast/JValue.scala index ec97ce76..59c9afc3 100644 --- a/ast/shared/src/main/scala/jawn/ast/JValue.scala +++ b/ast/shared/src/main/scala/jawn/ast/JValue.scala @@ -82,7 +82,7 @@ sealed abstract class JValue { object JValue { implicit val facade: Facade[JValue] = JawnFacade - implicit lazy val classTag: ClassTag[JValue] = ClassTag(classOf[JValue]) + implicit private[jawn] lazy val classTag: ClassTag[JValue] = ClassTag(classOf[JValue]) } sealed abstract class JAtom extends JValue {