Cached API tables and cut allocations in the PlayDate bindings target.

This commit is contained in:
2026-07-25 10:43:32 +02:00
parent 6594794cec
commit dfeadabfb6
20 changed files with 272 additions and 89 deletions
+6 -4
View File
@@ -58,12 +58,14 @@ extension String {
/// Copies the string into a newly allocated null-terminated C string.
/// The caller owns the memory and must free it with `deallocate()`.
func copiedPlaydateCString() -> UnsafeMutablePointer<CChar> {
let utf8 = ContiguousArray(self.utf8)
let buffer = UnsafeMutablePointer<CChar>.allocate(capacity: utf8.count + 1)
for (index, byte) in utf8.enumerated() {
let count = utf8.count
let buffer = UnsafeMutablePointer<CChar>.allocate(capacity: count + 1)
var index = 0
for byte in utf8 {
buffer[index] = CChar(bitPattern: byte)
index += 1
}
buffer[utf8.count] = 0
buffer[count] = 0
return buffer
}
}