Skip to content

Commit

Permalink
Fix performance regression in KotlinSuppressCache.isSuppressedByAnnot…
Browse files Browse the repository at this point in the history
…ated

After a seemingly innocent refactoring in 61548a0, we've lost the
optimization that was enabled by the suppressorAbove logic in
isSuppressedByAnnotated.
  • Loading branch information
udalov committed Nov 24, 2020
1 parent efee3ea commit ed481ad
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ abstract class KotlinSuppressCache {
val suppressor = getOrCreateSuppressor(annotated)
if (suppressor.isSuppressed(suppressionKey, severity)) return true

val annotatedAbove = KtStubbedPsiUtil.getPsiOrStubParent(annotated, KtAnnotated::class.java, true) ?: return false
val annotatedAbove = KtStubbedPsiUtil.getPsiOrStubParent(suppressor.annotatedElement, KtAnnotated::class.java, true) ?: return false

val suppressed = isSuppressedByAnnotated(suppressionKey, severity, annotatedAbove, debugDepth + 1)
val suppressorAbove = suppressors[annotatedAbove]
Expand All @@ -130,9 +130,9 @@ abstract class KotlinSuppressCache {
suppressors.getOrPut(annotated) {
val strings = getSuppressingStrings(annotated)
when (strings.size) {
0 -> EmptySuppressor
1 -> SingularSuppressor(strings.first())
else -> MultiSuppressor(strings)
0 -> EmptySuppressor(annotated)
1 -> SingularSuppressor(annotated, strings.first())
else -> MultiSuppressor(annotated, strings)
}
}

Expand Down Expand Up @@ -170,7 +170,7 @@ abstract class KotlinSuppressCache {
severity == Severity.WARNING && "warnings" in strings || key in strings
}

private abstract class Suppressor {
private abstract class Suppressor(val annotatedElement: KtAnnotated) {
open fun isSuppressed(diagnostic: Diagnostic): Boolean =
isSuppressed(getDiagnosticSuppressKey(diagnostic), diagnostic.severity)

Expand All @@ -180,13 +180,13 @@ abstract class KotlinSuppressCache {
abstract fun dominates(other: Suppressor): Boolean
}

private object EmptySuppressor : Suppressor() {
private class EmptySuppressor(annotated: KtAnnotated) : Suppressor(annotated) {
override fun isSuppressed(diagnostic: Diagnostic): Boolean = false
override fun isSuppressed(suppressionKey: String, severity: Severity): Boolean = false
override fun dominates(other: Suppressor): Boolean = this === other
override fun dominates(other: Suppressor): Boolean = other is EmptySuppressor
}

private class SingularSuppressor(private val string: String) : Suppressor() {
private class SingularSuppressor(annotated: KtAnnotated, private val string: String) : Suppressor(annotated) {
override fun isSuppressed(suppressionKey: String, severity: Severity): Boolean {
return isSuppressedByStrings(suppressionKey, ImmutableSet.of(string), severity)
}
Expand All @@ -196,7 +196,7 @@ abstract class KotlinSuppressCache {
}
}

private class MultiSuppressor(private val strings: Set<String>) : Suppressor() {
private class MultiSuppressor(annotated: KtAnnotated, private val strings: Set<String>) : Suppressor(annotated) {
override fun isSuppressed(suppressionKey: String, severity: Severity): Boolean {
return isSuppressedByStrings(suppressionKey, strings, severity)
}
Expand Down

0 comments on commit ed481ad

Please sign in to comment.