Skip to content

Commit

Permalink
Merge pull request #547 from agourlay/cache-JValue-ClassTag
Browse files Browse the repository at this point in the history
Optimize UnwrapArray parser by caching JValue ClassTag
  • Loading branch information
rossabaker authored Jun 26, 2023
2 parents 6eb7705 + c61b951 commit 1249411
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ast/shared/src/main/scala/jawn/ast/JValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package ast

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")
Expand Down Expand Up @@ -81,6 +82,7 @@ sealed abstract class JValue {

object JValue {
implicit val facade: Facade[JValue] = JawnFacade
implicit private[jawn] lazy val classTag: ClassTag[JValue] = ClassTag(classOf[JValue])
}

sealed abstract class JAtom extends JValue {
Expand Down
2 changes: 1 addition & 1 deletion ast/shared/src/main/scala/jawn/ast/JawnFacade.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 1249411

Please sign in to comment.