diff --git a/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt b/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt index bc8e56e6ba7..0b120951773 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt @@ -88,49 +88,47 @@ internal abstract class AbstractCharClass : SpecialToken() { private val surrogates_ = AtomicReference(null) - val surrogates: AbstractCharClass - get() { - surrogates_.value?.let { - return it - } - val surrogates = lowHighSurrogates - val result = object : AbstractCharClass() { - override fun contains(ch: Int): Boolean { - val index = ch - Char.MIN_SURROGATE.toInt() + fun classWithSurrogates(): AbstractCharClass { + surrogates_.value?.let { + return it + } + val surrogates = lowHighSurrogates + val result = object : AbstractCharClass() { + override fun contains(ch: Int): Boolean { + val index = ch - Char.MIN_SURROGATE.toInt() - return if (index >= 0 && index < AbstractCharClass.SURROGATE_CARDINALITY) { - this.altSurrogates xor surrogates[index] - } else { - false - } + return if (index >= 0 && index < AbstractCharClass.SURROGATE_CARDINALITY) { + this.altSurrogates xor surrogates[index] + } else { + false } } - result.setNegative(this.altSurrogates) - surrogates_.compareAndSet(null, result.freeze()) - return surrogates_.value!! } + result.setNegative(this.altSurrogates) + surrogates_.compareAndSet(null, result.freeze()) + return surrogates_.value!! + } // We cannot cache this class as we've done with surrogates above because // here is a circular reference between it and AbstractCharClass. - val withoutSurrogates: AbstractCharClass - get() { - val result = object : AbstractCharClass() { - override fun contains(ch: Int): Boolean { - val index = ch - Char.MIN_SURROGATE.toInt() + fun classWithoutSurrogates(): AbstractCharClass { + val result = object : AbstractCharClass() { + override fun contains(ch: Int): Boolean { + val index = ch - Char.MIN_SURROGATE.toInt() - val containslHS = if (index >= 0 && index < AbstractCharClass.SURROGATE_CARDINALITY) - this.altSurrogates xor this@AbstractCharClass.lowHighSurrogates.get(index) - else - false + val containslHS = if (index >= 0 && index < AbstractCharClass.SURROGATE_CARDINALITY) + this.altSurrogates xor this@AbstractCharClass.lowHighSurrogates.get(index) + else + false - return this@AbstractCharClass.contains(ch) && !containslHS - } + return this@AbstractCharClass.contains(ch) && !containslHS } - result.setNegative(isNegative()) - result.mayContainSupplCodepoints = mayContainSupplCodepoints - return result } + result.setNegative(isNegative()) + result.mayContainSupplCodepoints = mayContainSupplCodepoints + return result + } /** * Sets this CharClass to negative form, i.e. if they will add some characters and after that set this diff --git a/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt b/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt index b56877ccc18..e114670218d 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt @@ -774,13 +774,13 @@ internal class Pattern(val pattern: String, flags: Int = 0) { private fun processRangeSet(charClass: AbstractCharClass): AbstractSet { if (charClass.hasLowHighSurrogates()) { - val lowHighSurrRangeSet = SurrogateRangeSet(charClass.surrogates) + val lowHighSurrRangeSet = SurrogateRangeSet(charClass.classWithSurrogates()) if (charClass.mayContainSupplCodepoints) { - return CompositeRangeSet(SupplementaryRangeSet(charClass.withoutSurrogates, hasFlag(CASE_INSENSITIVE)), lowHighSurrRangeSet) + return CompositeRangeSet(SupplementaryRangeSet(charClass.classWithoutSurrogates(), hasFlag(CASE_INSENSITIVE)), lowHighSurrRangeSet) } - return CompositeRangeSet(RangeSet(charClass.withoutSurrogates, hasFlag(CASE_INSENSITIVE)), lowHighSurrRangeSet) + return CompositeRangeSet(RangeSet(charClass.classWithoutSurrogates(), hasFlag(CASE_INSENSITIVE)), lowHighSurrRangeSet) } if (charClass.mayContainSupplCodepoints) {