Created
April 10, 2020 15:27
-
-
Save kmuralidharan91/c404c5181b700004fead2856e8ad2db4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension ArraySlice { | |
private func array() -> [Element] { | |
return Array(self) | |
} | |
func withAlignedBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R { | |
if startIndex == 0 || startIndex % MemoryLayout<R>.alignment == 0 { | |
return try self.withUnsafeBytes(body) | |
} else { | |
return try self.array().withUnsafeBytes(body) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment