block property: cache hashCode

That makes checking if a block is waterlogged WAY faster
This commit is contained in:
Moritz Zwerger 2023-12-08 20:59:37 +01:00
parent 4619101de2
commit 36d43bc8fb
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -17,6 +17,7 @@ package de.bixilon.minosoft.data.registries.blocks.properties
abstract class BlockProperty<T>(
val name: String,
) : Iterable<T> {
private val hashCode = name.hashCode()
override fun toString(): String {
return name
@ -25,11 +26,12 @@ abstract class BlockProperty<T>(
abstract fun parse(value: Any): T
override fun hashCode(): Int {
return name.hashCode()
return hashCode
}
override fun equals(other: Any?): Boolean {
if (other !is BlockProperty<*>) return false
if (hashCode != other.hashCode) return false
return other.name == name
}
}