@@ -167,7 +167,7 @@ internal inline fun ByteArray.packNumberAllElsePartial(
167
167
ushr : (bits: Int ) -> Byte ,
168
168
): ByteArray {
169
169
// Check endIndex first
170
- return if (sourceIndexEnd == numberSizeBytes && sourceIndexStart == 0 ) packNumber()
170
+ return if (sourceIndexEnd == numberSizeBytes && sourceIndexStart == 0 ) packNumber(this )
171
171
else packNumberPartial(destOffset, sourceIndexStart, sourceIndexEnd, ushr)
172
172
}
173
173
@@ -177,9 +177,9 @@ internal inline fun ByteArray.packNumberPartial(
177
177
sourceIndexEnd : Int ,
178
178
ushr : (bits: Int ) -> Byte ,
179
179
): ByteArray {
180
- var pos = destOffset
180
+ var destPos = destOffset
181
181
for (i in sourceIndexStart.. < sourceIndexEnd) {
182
- this [pos ++ ] = ushr(Byte .SIZE_BITS * i)
182
+ this [destPos ++ ] = ushr(Byte .SIZE_BITS * i)
183
183
}
184
184
return this
185
185
}
@@ -191,20 +191,23 @@ internal inline fun ByteArray.packArray(
191
191
numberSizeBytes : Int ,
192
192
packNumber : ByteArray .(sourcePos: Int , destPos: Int ) -> ByteArray ,
193
193
): ByteArray {
194
- for (i in sourceIndexStart.. < sourceIndexEnd) {
195
- packNumber(i, (i * numberSizeBytes) + destOffset)
194
+ var destPos = destOffset
195
+ var sourcePos = sourceIndexStart
196
+ while (sourcePos < sourceIndexEnd) {
197
+ packNumber(this , sourcePos++ , destPos)
198
+ destPos + = numberSizeBytes
196
199
}
197
200
return this
198
201
}
199
202
200
- internal inline fun <Dest : Any > Dest .packArray (
203
+ internal inline fun <TypedArray : Any > TypedArray .packArray (
201
204
source : ByteArray ,
202
205
destOffset : Int ,
203
206
sourceIndexStart : Int ,
204
207
sourceIndexEnd : Int ,
205
208
numberSizeBytes : Int ,
206
209
unpackNumber : ByteArray .(sourcePos: Int , destPos: Int ) -> Unit ,
207
- ): Dest {
210
+ ): TypedArray {
208
211
var destPos = destOffset
209
212
var sourcePos = sourceIndexStart
210
213
while (sourcePos < sourceIndexEnd) {
0 commit comments