Skip to content

Commit b437a4c

Browse files
committed
Use null character \u0000, instead of a space, when back-filling CharArray
1 parent 9a88a30 commit b437a4c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/Encoder.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ public sealed class Encoder<C: EncoderDecoder.Config>(config: C): Decoder<C>(con
223223
val sb = StringBuilder(maxSize)
224224
encoder.encode(this, sb::append)
225225
val result = sb.toString()
226-
if (encoder.config.backFillBuffers) sb.wipe()
226+
if (encoder.config.backFillBuffers) {
227+
sb.wipe()
228+
}
227229
result
228230
}
229231
}
@@ -250,7 +252,7 @@ public sealed class Encoder<C: EncoderDecoder.Config>(config: C): Decoder<C>(con
250252
if (i == maxSize) return@block a
251253
val copy = a.copyOf(i)
252254
if (encoder.config.backFillBuffers) {
253-
a.fill(' ', 0, i)
255+
a.fill('\u0000', 0, i)
254256
}
255257
copy
256258
}

library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/EncoderDecoder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ public abstract class EncoderDecoder<C: EncoderDecoder.Config>(config: C): Encod
122122
* data (e.g. a [StringBuilder], [CharArray], or [ByteArray]). Depending on the underlying
123123
* encoding/decoding operation, such as an array over-allocation due to [encodeOutMaxSize]
124124
* or [decodeOutMaxSize], those initially allocated buffers may not be returned as the
125-
* function's result. Prior versions of this library always back-filled them with `0` or a
126-
* space character, but that can be computationally expensive for large datasets and
125+
* function's result. Prior versions of this library always back-filled them with `0` or the
126+
* null character `\u0000`, but that can be computationally expensive for large datasets and
127127
* potentially unnecessary if data is known to not be sensitive in nature.
128128
*
129129
* If `true`, any non-result buffer allocations are back-filled before being de-referenced

0 commit comments

Comments
 (0)