IR: cache IdSignature hashCode for better performance in maps
This commit is contained in:
committed by
teamcityserver
parent
76f0684d7c
commit
e0570d98b2
@@ -95,8 +95,9 @@ sealed class IdSignature {
|
|||||||
other is CommonSignature && packageFqName == other.packageFqName && declarationFqName == other.declarationFqName &&
|
other is CommonSignature && packageFqName == other.packageFqName && declarationFqName == other.declarationFqName &&
|
||||||
id == other.id && mask == other.mask
|
id == other.id && mask == other.mask
|
||||||
|
|
||||||
override fun hashCode(): Int =
|
private val hashCode = ((packageFqName.hashCode() * 31 + declarationFqName.hashCode()) * 31 + id.hashCode()) * 31 + mask.hashCode()
|
||||||
((packageFqName.hashCode() * 31 + declarationFqName.hashCode()) * 31 + id.hashCode()) * 31 + mask.hashCode()
|
|
||||||
|
override fun hashCode(): Int = hashCode
|
||||||
}
|
}
|
||||||
|
|
||||||
class CompositeSignature(val container: IdSignature, val inner: IdSignature) : IdSignature() {
|
class CompositeSignature(val container: IdSignature, val inner: IdSignature) : IdSignature() {
|
||||||
@@ -155,7 +156,9 @@ sealed class IdSignature {
|
|||||||
if (other is AccessorSignature) accessorSignature == other.accessorSignature
|
if (other is AccessorSignature) accessorSignature == other.accessorSignature
|
||||||
else accessorSignature == other
|
else accessorSignature == other
|
||||||
|
|
||||||
override fun hashCode(): Int = accessorSignature.hashCode()
|
private val hashCode = accessorSignature.hashCode()
|
||||||
|
|
||||||
|
override fun hashCode(): Int = hashCode
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileSignature(val fileSymbol: IrFileSymbol) : IdSignature() {
|
class FileSignature(val fileSymbol: IrFileSymbol) : IdSignature() {
|
||||||
@@ -281,11 +284,9 @@ sealed class IdSignature {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
private val hashCode = 31 * memberSignature.hashCode() + overriddenSignatures.hashCode()
|
||||||
var result = memberSignature.hashCode()
|
|
||||||
result = 31 * result + overriddenSignatures.hashCode()
|
override fun hashCode(): Int = hashCode
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileLocalSignature(val container: IdSignature, val id: Long, val description: String? = null) : IdSignature() {
|
class FileLocalSignature(val container: IdSignature, val id: Long, val description: String? = null) : IdSignature() {
|
||||||
@@ -311,7 +312,9 @@ sealed class IdSignature {
|
|||||||
override fun equals(other: Any?): Boolean =
|
override fun equals(other: Any?): Boolean =
|
||||||
other is FileLocalSignature && id == other.id && container == other.container
|
other is FileLocalSignature && id == other.id && container == other.container
|
||||||
|
|
||||||
override fun hashCode(): Int = container.hashCode() * 31 + id.hashCode()
|
private val hashCode = container.hashCode() * 31 + id.hashCode()
|
||||||
|
|
||||||
|
override fun hashCode(): Int = hashCode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to reference local variable and value parameters in function
|
// Used to reference local variable and value parameters in function
|
||||||
@@ -360,7 +363,9 @@ sealed class IdSignature {
|
|||||||
override fun equals(other: Any?): Boolean =
|
override fun equals(other: Any?): Boolean =
|
||||||
other is GlobalFileLocalSignature && id == other.id && container == other.container && filePath == other.filePath
|
other is GlobalFileLocalSignature && id == other.id && container == other.container && filePath == other.filePath
|
||||||
|
|
||||||
override fun hashCode(): Int = (container.hashCode() * 31 + id.hashCode()) * 31 + filePath.hashCode()
|
private val hashCode = (container.hashCode() * 31 + id.hashCode()) * 31 + filePath.hashCode()
|
||||||
|
|
||||||
|
override fun hashCode(): Int = hashCode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to reference local variable and value parameters in function
|
// Used to reference local variable and value parameters in function
|
||||||
@@ -375,18 +380,20 @@ sealed class IdSignature {
|
|||||||
|
|
||||||
override fun packageFqName(): FqName = error("Is not supported for Local ID")
|
override fun packageFqName(): FqName = error("Is not supported for Local ID")
|
||||||
|
|
||||||
override fun render(): String = "#$id"
|
override fun render(): String = "#$id from ${filePath.split('/').last()}"
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean =
|
override fun equals(other: Any?): Boolean =
|
||||||
other is GlobalScopeLocalDeclaration && id == other.id && filePath == other.filePath
|
other is GlobalScopeLocalDeclaration && id == other.id && filePath == other.filePath
|
||||||
|
|
||||||
override fun hashCode(): Int = id * 31 + filePath.hashCode()
|
private val hashCode = id * 31 + filePath.hashCode()
|
||||||
|
|
||||||
|
override fun hashCode(): Int = hashCode
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoweredDeclarationSignature(val original: IdSignature, val stage: Int, val index: Int) : IdSignature() {
|
class LoweredDeclarationSignature(val original: IdSignature, val stage: Int, val index: Int) : IdSignature() {
|
||||||
override val isPubliclyVisible: Boolean get() = true
|
override val isPubliclyVisible: Boolean get() = true
|
||||||
|
|
||||||
override val hasTopLevel: Boolean get() = false
|
override val hasTopLevel: Boolean get() = true
|
||||||
|
|
||||||
override fun topLevelSignature(): IdSignature = this
|
override fun topLevelSignature(): IdSignature = this
|
||||||
|
|
||||||
@@ -400,9 +407,9 @@ sealed class IdSignature {
|
|||||||
return other is LoweredDeclarationSignature && original == other.original && stage == other.stage && index == other.index
|
return other is LoweredDeclarationSignature && original == other.original && stage == other.stage && index == other.index
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
private val hashCode = (index * 31 + stage) * 31 + original.hashCode()
|
||||||
return (index * 31 + stage) * 31 + original.hashCode()
|
|
||||||
}
|
override fun hashCode(): Int = hashCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user