Skip to content

Commit c63c7d0

Browse files
committed
Cache hashCode() in FuncCtx
Since there may be circular references in it
1 parent 7ad1206 commit c63c7d0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/org/klesun/deep_js_completion/contexts/FuncCtx.scala

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ case class FuncCtx(
2323
closurePsi: Option[JSFunction] = None,
2424
closureCtx: Option[IFuncCtx] = None,
2525
) extends IFuncCtx {
26+
var hashCodeField: Option[Int] = None
2627

2728
def getSearch = search
2829

@@ -73,7 +74,17 @@ case class FuncCtx(
7374
}
7475

7576
override def hashCode(): Int = {
76-
getHashValues().hashCode()
77+
if (hashCodeField.isEmpty) {
78+
val startMs = System.currentTimeMillis
79+
val hashValues = getHashValues()
80+
val hashCode = hashValues.hashCode()
81+
val deltaMs = System.currentTimeMillis - startMs
82+
if (deltaMs > 0) {
83+
Console.println("hashCode in " + deltaMs + " ms " + hashValues)
84+
}
85+
hashCodeField = Some(hashCode)
86+
}
87+
hashCodeField.get
7788
}
7889

7990
override def equals(that: Any): Boolean = {

0 commit comments

Comments
 (0)