Skip to content

Instantly share code, notes, and snippets.

@ainame
Created June 20, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ainame/8629facc6b734ad7f5fa5f9224c42ff7 to your computer and use it in GitHub Desktop.
Save ainame/8629facc6b734ad7f5fa5f9224c42ff7 to your computer and use it in GitHub Desktop.
Fast?
import Darwin
let string = "hello world"
var array = [UInt8]()
string.withCString { ptr in
print("strlen: \(strlen(ptr))")
let length = strlen(ptr)
var currentPtr = ptr
var i = 0
while i != length {
print("pointee: \(currentPtr.pointee), char: \(Unicode.Scalar(Int(currentPtr.pointee))!)")
array.append(UInt8(currentPtr.pointee))
currentPtr = currentPtr.successor()
i += 1
}
}
print(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment