diff --git a/benchmarks/README.md b/benchmarks/README.md index 456315f8..f4ed29e9 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -15,11 +15,6 @@ workflow run on the [GitHub Actions][url-actions] tab of the repository. ./gradlew jvmBenchmark ``` -- Run Js: - ```shell - ./gradlew jsBenchmark - ``` - - Run WasmJs: ```shell ./gradlew wasmJsBenchmark diff --git a/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/Encoder.kt b/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/Encoder.kt index 365a1f10..b5a8c4ff 100644 --- a/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/Encoder.kt +++ b/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/Encoder.kt @@ -221,7 +221,7 @@ public sealed class Encoder(config: C): Decoder(con public fun ByteArray.encodeToString(encoder: Encoder<*>): String { return encoder.encodeOutMaxSizeOrFail(size) { maxSize -> val sb = StringBuilder(maxSize) - encoder.encode(this, sb::append) + encoder.encode(this, _outFeed = { OutFeed(sb::append) }) val result = sb.toString() if (encoder.config.backFillBuffers) { sb.wipe() @@ -248,7 +248,7 @@ public sealed class Encoder(config: C): Decoder(con return encoder.encodeOutMaxSizeOrFail(size) block@ { maxSize -> var i = 0 val a = CharArray(maxSize) - encoder.encode(this) { c -> a[i++] = c } + encoder.encode(this, _outFeed = { OutFeed { c -> a[i++] = c } }) if (i == maxSize) return@block a val copy = a.copyOf(i) if (encoder.config.backFillBuffers) { @@ -274,7 +274,7 @@ public sealed class Encoder(config: C): Decoder(con return encoder.encodeOutMaxSizeOrFail(size) block@ { maxSize -> var i = 0 val a = ByteArray(maxSize) - encoder.encode(this) { char -> a[i++] = char.code.toByte() } + encoder.encode(this, _outFeed = { OutFeed { char -> a[i++] = char.code.toByte() } }) if (i == maxSize) return@block a val copy = a.copyOf(i) if (encoder.config.backFillBuffers) { diff --git a/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/EncoderDecoder.kt b/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/EncoderDecoder.kt index 29dbd607..82c097c0 100644 --- a/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/EncoderDecoder.kt +++ b/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/EncoderDecoder.kt @@ -807,6 +807,6 @@ private inline fun checkMaxEmitSize(size: Int, parameterName: () -> String) { } @Suppress("NOTHING_TO_INLINE") -internal inline fun negativeEncodingSizeException(outSize: Number): EncodingSizeException { +private inline fun negativeEncodingSizeException(outSize: Number): EncodingSizeException { return EncodingSizeException("Calculated output of Size[$outSize] was negative") } diff --git a/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/internal/-Encoder.kt b/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/internal/-Encoder.kt index f35ed0d8..b42841ab 100644 --- a/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/internal/-Encoder.kt +++ b/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/internal/-Encoder.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("LocalVariableName", "NOTHING_TO_INLINE") +@file:Suppress("LocalVariableName") package io.matthewnelson.encoding.core.internal @@ -37,19 +37,20 @@ internal inline fun Encoder<*>.encodeOutMaxSizeOrFail( _block: (maxSize: Int) -> T, ): T { contract { callsInPlace(_block, InvocationKind.AT_MOST_ONCE) } - val maxSize = config.encodeOutMaxSize(size.toLong()) if (maxSize > MAX_ENCODE_OUT_SIZE) { throw Config.outSizeExceedsMaxEncodingSizeException(maxSize, MAX_ENCODE_OUT_SIZE) } - return _block(maxSize.toInt()) } +@OptIn(ExperimentalContracts::class) internal inline fun Encoder.encode( data: ByteArray, - out: Encoder.OutFeed, + _outFeed: () -> Encoder.OutFeed, ) { + contract { callsInPlace(_outFeed, InvocationKind.AT_MOST_ONCE) } if (data.isEmpty()) return + val out = _outFeed() newEncoderFeed(out).use { feed -> data.forEach { b -> feed.consume(b) } } }