Skip to content

Commit

Permalink
fix Swift 4.0 compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Weiß committed Aug 29, 2018
1 parent 8220bdf commit f42c836
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/NIO/ByteBuffer-core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ let sysFree: @convention(c) (UnsafeMutableRawPointer?) -> Void = free

internal func initializeMemory<T>(as type: T.Type, repeating repeatedValue: T) -> UnsafeMutableBufferPointer<T> {
let ptr = self.bindMemory(to: T.self)
ptr.initialize(from: repeatElement(repeatedValue, count: self.count / MemoryLayout<T>.stride))
_ = ptr.initialize(from: repeatElement(repeatedValue, count: self.count / MemoryLayout<T>.stride))
return ptr
}

public func copyMemory(from src: UnsafeRawBufferPointer) {
self.copyBytes(from: src)
}

internal func bindMemory<T>(to type: T.Type) -> UnsafeMutableBufferPointer<T> {
guard let base = self.baseAddress else {
return UnsafeMutableBufferPointer<T>(start: nil, count: 0)
}
let capacity = count / MemoryLayout<T>.stride
let ptr = base.bindMemory(to: T.self, capacity: capacity)
return UnsafeMutableBufferPointer<T>(start: ptr, count: capacity)
}
}
#endif

Expand Down

0 comments on commit f42c836

Please sign in to comment.