Skip to content

Commit

Permalink
Forgot to release the buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peanuuutz committed Sep 29, 2023
1 parent 22a7042 commit f9f2703
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion core/src/commonMain/kotlin/net/peanuuutz/tomlkt/Toml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import kotlinx.serialization.StringFormat
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.serializer
import net.peanuuutz.tomlkt.Toml.Default
import net.peanuuutz.tomlkt.internal.BufferPool
import net.peanuuutz.tomlkt.internal.NonPrimitiveKeyException
import net.peanuuutz.tomlkt.internal.TomlDecodingException
import net.peanuuutz.tomlkt.internal.TomlEncodingException
Expand Down Expand Up @@ -260,7 +261,12 @@ public sealed class Toml(
* [TomlTable].
*/
public fun parseToTomlTable(reader: TomlReader): TomlTable {
return TomlFileParser(reader).parse()
val buffer = BufferPool.take()
return try {
TomlFileParser(reader, buffer).parse()
} finally {
BufferPool.release(buffer)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import net.peanuuutz.tomlkt.TomlReader
import net.peanuuutz.tomlkt.TomlTable
import net.peanuuutz.tomlkt.internal.BareKeyConstraints
import net.peanuuutz.tomlkt.internal.BareKeyRegex
import net.peanuuutz.tomlkt.internal.BufferPool
import net.peanuuutz.tomlkt.internal.Comment
import net.peanuuutz.tomlkt.internal.DecimalConstraints
import net.peanuuutz.tomlkt.internal.DecimalOrSignConstraints
Expand All @@ -47,9 +46,10 @@ import net.peanuuutz.tomlkt.internal.unescape
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

internal class TomlFileParser(private val reader: TomlReader) {
private val buffer: CharArray = BufferPool.take()

internal class TomlFileParser(
private val reader: TomlReader,
private val buffer: CharArray
) {
private val bufferSize: Int = buffer.size

private var currentLineNumber: Int = 1
Expand Down

0 comments on commit f9f2703

Please sign in to comment.