Skip to content

Commit 4519045

Browse files
committed
Cache hashCode of EtsClassSignature
1 parent fa2a850 commit 4519045

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

jacodb-ets/src/main/kotlin/org/jacodb/ets/model/Signatures.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,31 @@ data class EtsClassSignature(
7979
}
8080
}
8181

82+
private val cachedHashCode: Int = run {
83+
var result = name.hashCode()
84+
result = 31 * result + file.hashCode()
85+
result = 31 * result + (namespace?.hashCode() ?: 0)
86+
result
87+
}
88+
89+
override fun hashCode(): Int {
90+
return cachedHashCode
91+
}
92+
93+
override fun equals(other: Any?): Boolean {
94+
if (this === other) return true
95+
if (javaClass != other?.javaClass) return false
96+
97+
other as EtsClassSignature
98+
99+
if (cachedHashCode != other.cachedHashCode) return false
100+
if (name != other.name) return false
101+
if (file != other.file) return false
102+
if (namespace != other.namespace) return false
103+
104+
return true
105+
}
106+
82107
companion object {
83108
val UNKNOWN = EtsClassSignature(
84109
name = UNKNOWN_CLASS_NAME,

0 commit comments

Comments
 (0)