Skip to content

Commit

Permalink
fast util key map
Browse files Browse the repository at this point in the history
  • Loading branch information
ahirreddy committed Dec 29, 2023
1 parent 2530189 commit 73a2283
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ lazy val main = (project in file("sjsonnet"))
"org.scala-lang.modules" %% "scala-collection-compat" % "2.4.0",
"org.tukaani" % "xz" % "1.8",
"org.yaml" % "snakeyaml" % "1.30",
"it.unimi.dsi" % "fastutil" % "8.5.12"
),
libraryDependencies ++= Seq(
"com.lihaoyi" %% "utest" % "0.7.7",
Expand Down
8 changes: 4 additions & 4 deletions sjsonnet/src/sjsonnet/Val.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ object Val{
triggerAsserts: Val.Obj => Unit,
`super`: Obj,
valueCache: mutable.HashMap[Any, Val] = mutable.HashMap.empty[Any, Val],
private[this] var allKeys: util.LinkedHashMap[String, java.lang.Boolean] = null) extends Literal with Expr.ObjBody {
private[this] var allKeys: it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap[String] = null) extends Literal with Expr.ObjBody {
var asserting: Boolean = false

def getSuper = `super`
Expand Down Expand Up @@ -176,7 +176,7 @@ object Val{
def prettyName = "object"
override def asObj: Val.Obj = this

private def gatherKeys(mapping: util.LinkedHashMap[String, java.lang.Boolean]): Unit = {
private def gatherKeys(mapping: it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap[String]): Unit = {
if(static) mapping.putAll(allKeys)
else {
if(`super` != null) `super`.gatherKeys(mapping)
Expand All @@ -191,7 +191,7 @@ object Val{

private def getAllKeys = {
if(allKeys == null) {
allKeys = new util.LinkedHashMap[String, java.lang.Boolean]
allKeys = new it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap[String]
gatherKeys(allKeys)
}
allKeys
Expand Down Expand Up @@ -299,7 +299,7 @@ object Val{

def staticObject(pos: Position, fields: Array[Expr.Member.Field]): Obj = {
val cache = mutable.HashMap.empty[Any, Val]
val allKeys = new util.LinkedHashMap[String, java.lang.Boolean]
val allKeys = new it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap[String]()
fields.foreach {
case Expr.Member.Field(_, Expr.FieldName.Fixed(k), _, _, _, rhs: Val.Literal) =>
cache.put(k, rhs)
Expand Down
2 changes: 1 addition & 1 deletion sjsonnet/src/sjsonnet/ValVisitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ValVisitor(pos: Position) extends JsVisitor[Val, Val] { self =>

def visitObject(length: Int, index: Int): ObjVisitor[Val, Val] = new ObjVisitor[Val, Val] {
val cache = mutable.HashMap.empty[Any, Val]
val allKeys = new util.LinkedHashMap[String, java.lang.Boolean]
val allKeys = new it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap[String]
var key: String = null
def subVisitor: Visitor[_, _] = self
def visitKey(index: Int) = upickle.core.StringVisitor
Expand Down

0 comments on commit 73a2283

Please sign in to comment.