1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 11:37:32 +03:00

Refactor slightly

This commit is contained in:
Tae Won Ha 2019-03-13 23:07:33 +01:00
parent 38fb91f6c0
commit c9facb60ea
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
2 changed files with 17 additions and 17 deletions

View File

@ -14,6 +14,23 @@ extension Array where Element: Hashable {
}
}
extension Array {
func data() -> Data {
return self.withUnsafeBytes { pointer in
if let baseAddr = pointer.baseAddress {
return Data(bytes: baseAddr, count: pointer.count)
}
let newPointer = UnsafeMutablePointer<Element>.allocate(capacity: self.count)
for (index, element) in self.enumerated() {
newPointer[index] = element
}
return Data(bytesNoCopy: newPointer, count: self.count, deallocator: .free)
}
}
}
extension RandomAccessCollection where Index == Int {
func parallelMap<T>(

View File

@ -364,20 +364,3 @@ class UiBridge {
}
private let timeout = CFTimeInterval(5)
private extension Array {
func data() -> Data {
return self.withUnsafeBytes { pointer in
if let baseAddr = pointer.baseAddress {
return Data(bytes: baseAddr, count: pointer.count)
}
let newPointer = UnsafeMutablePointer<Element>.allocate(capacity: self.count)
for (index, element) in self.enumerated() {
newPointer[index] = element
}
return Data(bytesNoCopy: newPointer, count: self.count, deallocator: .free)
}
}
}