[regex] Fix memory leak in debug mode
This commit is contained in:
committed by
Ilya Matveev
parent
a82dd82402
commit
f8bbd5eff0
@@ -93,14 +93,16 @@ internal abstract class AbstractCharClass : SpecialToken() {
|
|||||||
surrogates_.value?.let {
|
surrogates_.value?.let {
|
||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
|
val surrogates = lowHighSurrogates
|
||||||
val result = object : AbstractCharClass() {
|
val result = object : AbstractCharClass() {
|
||||||
override fun contains(ch: Int): Boolean {
|
override fun contains(ch: Int): Boolean {
|
||||||
val index = ch - Char.MIN_SURROGATE.toInt()
|
val index = ch - Char.MIN_SURROGATE.toInt()
|
||||||
|
|
||||||
return if (index >= 0 && index < AbstractCharClass.SURROGATE_CARDINALITY)
|
return if (index >= 0 && index < AbstractCharClass.SURROGATE_CARDINALITY) {
|
||||||
this.altSurrogates xor this@AbstractCharClass.lowHighSurrogates.get(index)
|
this.altSurrogates xor surrogates[index]
|
||||||
else
|
} else {
|
||||||
false
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.setNegative(this.altSurrogates)
|
result.setNegative(this.altSurrogates)
|
||||||
@@ -109,12 +111,10 @@ internal abstract class AbstractCharClass : SpecialToken() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private val withoutSurrogates_ = AtomicReference<AbstractCharClass?>(null)
|
// 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
|
val withoutSurrogates: AbstractCharClass
|
||||||
get() {
|
get() {
|
||||||
withoutSurrogates_.value?.let {
|
|
||||||
return it
|
|
||||||
}
|
|
||||||
val result = object : AbstractCharClass() {
|
val result = object : AbstractCharClass() {
|
||||||
override fun contains(ch: Int): Boolean {
|
override fun contains(ch: Int): Boolean {
|
||||||
val index = ch - Char.MIN_SURROGATE.toInt()
|
val index = ch - Char.MIN_SURROGATE.toInt()
|
||||||
@@ -129,11 +129,9 @@ internal abstract class AbstractCharClass : SpecialToken() {
|
|||||||
}
|
}
|
||||||
result.setNegative(isNegative())
|
result.setNegative(isNegative())
|
||||||
result.mayContainSupplCodepoints = mayContainSupplCodepoints
|
result.mayContainSupplCodepoints = mayContainSupplCodepoints
|
||||||
withoutSurrogates_ .compareAndSet(null, result.freeze())
|
return result
|
||||||
return withoutSurrogates_.value!!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets this CharClass to negative form, i.e. if they will add some characters and after that set this
|
* Sets this CharClass to negative form, i.e. if they will add some characters and after that set this
|
||||||
* class to negative it will accept all the characters except previously set ones.
|
* class to negative it will accept all the characters except previously set ones.
|
||||||
|
|||||||
Reference in New Issue
Block a user