diff --git a/kmp/shared-core/spm/Sources/SharedCoreKit/Data+KotlinByteArray.swift b/kmp/shared-core/spm/Sources/SharedCoreKit/Data+KotlinByteArray.swift index b9f956617f..1e4a63e625 100644 --- a/kmp/shared-core/spm/Sources/SharedCoreKit/Data+KotlinByteArray.swift +++ b/kmp/shared-core/spm/Sources/SharedCoreKit/Data+KotlinByteArray.swift @@ -4,24 +4,15 @@ import SharedCore extension Data { /// Kotlin's `ByteArray` has no `Data` bridge of its own, so every exported function taking - /// bytes needs this copy. + /// bytes needs this copy. It goes through `NSData` because the only element-wise alternative, + /// `KotlinByteArray.set(index:value:)`, costs one Objective-C message send per byte. var kotlinByteArray: KotlinByteArray { - let array = KotlinByteArray(size: Int32(count)) - for (offset, byte) in enumerated() { - array.set(index: Int32(offset), value: Int8(bitPattern: byte)) - } - return array + SharedBytes.shared.byteArray(data: self) } /// The reverse copy, for the exported functions that hand bytes back. Kotlin bytes are signed, - /// so anything above 0x7F comes across negative and has to be reinterpreted rather than - /// converted. + /// but a bulk copy moves the bit patterns unchanged, so nothing has to be reinterpreted here. init(_ array: KotlinByteArray) { - var bytes = [UInt8]() - bytes.reserveCapacity(Int(array.size)) - for index in 0..