Skip to content

Commit

Permalink
~fix modeReuseCache
Browse files Browse the repository at this point in the history
  • Loading branch information
sandwwraith committed Dec 9, 2020
1 parent bb559c5 commit bcd0b93
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class StreamingJsonEncoder(
private val composer: Composer,
override val json: Json,
private val mode: WriteMode,
private val modeReuseCache: Array<JsonEncoder?>
private val modeReuseCache: Array<JsonEncoder?>?
) : JsonEncoder, AbstractEncoder() {

internal constructor(
Expand All @@ -49,8 +49,10 @@ internal class StreamingJsonEncoder(

init {
val i = mode.ordinal
if (modeReuseCache[i] == null)
modeReuseCache[i] = this
if (modeReuseCache != null) {
if (modeReuseCache[i] !== null || modeReuseCache[i] !== this)
modeReuseCache[i] = this
}
}

override fun encodeJsonElement(element: JsonElement) {
Expand Down Expand Up @@ -91,7 +93,7 @@ internal class StreamingJsonEncoder(
return this
}

return modeReuseCache[newMode.ordinal] ?: StreamingJsonEncoder(composer, json, newMode, modeReuseCache)
return modeReuseCache?.get(newMode.ordinal) ?: StreamingJsonEncoder(composer, json, newMode, modeReuseCache)
}

override fun endStructure(descriptor: SerialDescriptor) {
Expand Down Expand Up @@ -151,7 +153,7 @@ internal class StreamingJsonEncoder(
ComposerForUnsignedNumbers(
composer.sb,
composer.json
), json, mode, modeReuseCache
), json, mode, null
)
else this
}
Expand Down

0 comments on commit bcd0b93

Please sign in to comment.