Data.withUnsafeBytes and type annotations
Swift Forums
Data.withUnsafeBytes and type annotations
Hi everyone, I'm searching through multi-gigabyte files for newlines, starting with let raw = try Data(contentsOf: url, options: .alwaysMapped) The following implementation compiles and works, but seems slow. raw.withUnsafeBytes { (buf: UnsafeRawBufferPointer) in if let ba: UnsafeRawPointer = buf.baseAddress { let ptr = ba.bindMemory(to: UInt8.self, capacity: raw.count) for i in 0..<raw.count { if ptr[i] == 0x0a {newlines.append(i)} } } } I want to try memchr but the f...
0 comments
No comments yet.