Skip to content

Commit

Permalink
Revert "Implement faster pointer rebasing. (apple#1696)"
Browse files Browse the repository at this point in the history
This reverts commit 4bf379b.
  • Loading branch information
Lukasa committed Jan 7, 2021
1 parent 8ea391a commit b2db50b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 56 deletions.
10 changes: 5 additions & 5 deletions Sources/NIO/ByteBuffer-aux.swift
Expand Up @@ -34,7 +34,7 @@ extension ByteBuffer {
// this is not technically correct because we shouldn't just bind
// the memory to `UInt8` but it's not a real issue either and we
// need to work around https://bugs.swift.org/browse/SR-9604
Array<UInt8>(UnsafeRawBufferPointer(fastRebase: ptr[range]).bindMemory(to: UInt8.self))
Array<UInt8>(UnsafeRawBufferPointer(rebasing: ptr[range]).bindMemory(to: UInt8.self))
}
}

Expand Down Expand Up @@ -139,7 +139,7 @@ extension ByteBuffer {
}
return self.withUnsafeReadableBytes { pointer in
assert(range.lowerBound >= 0 && (range.upperBound - range.lowerBound) <= pointer.count)
return String(decoding: UnsafeRawBufferPointer(fastRebase: pointer[range]), as: Unicode.UTF8.self)
return String(decoding: UnsafeRawBufferPointer(rebasing: pointer[range]), as: Unicode.UTF8.self)
}
}

Expand Down Expand Up @@ -210,7 +210,7 @@ extension ByteBuffer {
self.withVeryUnsafeMutableBytes { destCompleteStorage in
assert(destCompleteStorage.count >= index + allBytesCount)
let dest = destCompleteStorage[index ..< index + allBytesCount]
dispatchData.copyBytes(to: .init(fastRebase: dest), count: dest.count)
dispatchData.copyBytes(to: .init(rebasing: dest), count: dest.count)
}
return allBytesCount
}
Expand All @@ -228,7 +228,7 @@ extension ByteBuffer {
return nil
}
return self.withUnsafeReadableBytes { pointer in
return DispatchData(bytes: UnsafeRawBufferPointer(fastRebase: pointer[range]))
return DispatchData(bytes: UnsafeRawBufferPointer(rebasing: pointer[range]))
}
}

Expand Down Expand Up @@ -396,7 +396,7 @@ extension ByteBuffer {
precondition(count >= 0, "Can't write fewer than 0 bytes")
self.reserveCapacity(index + count)
self.withVeryUnsafeMutableBytes { pointer in
let dest = UnsafeMutableRawBufferPointer(fastRebase: pointer[index ..< index+count])
let dest = UnsafeMutableRawBufferPointer(rebasing: pointer[index ..< index+count])
_ = dest.initializeMemory(as: UInt8.self, repeating: byte)
}
return count
Expand Down
12 changes: 6 additions & 6 deletions Sources/NIO/ByteBuffer-core.swift
Expand Up @@ -379,7 +379,7 @@ public struct ByteBuffer {

@inlinable
mutating func _setBytesAssumingUniqueBufferAccess(_ bytes: UnsafeRawBufferPointer, at index: _Index) {
let targetPtr = UnsafeMutableRawBufferPointer(fastRebase: self._slicedStorageBuffer.dropFirst(Int(index)))
let targetPtr = UnsafeMutableRawBufferPointer(rebasing: self._slicedStorageBuffer.dropFirst(Int(index)))
targetPtr.copyMemory(from: bytes)
}

Expand All @@ -389,7 +389,7 @@ public struct ByteBuffer {
mutating func _setSlowPath<Bytes: Sequence>(bytes: Bytes, at index: _Index) -> _Capacity where Bytes.Element == UInt8 {
func ensureCapacityAndReturnStorageBase(capacity: Int) -> UnsafeMutablePointer<UInt8> {
self._ensureAvailableCapacity(_Capacity(capacity), at: index)
let newBytesPtr = UnsafeMutableRawBufferPointer(fastRebase: self._slicedStorageBuffer[Int(index) ..< Int(index) + Int(capacity)])
let newBytesPtr = UnsafeMutableRawBufferPointer(rebasing: self._slicedStorageBuffer[Int(index) ..< Int(index) + Int(capacity)])
return newBytesPtr.bindMemory(to: UInt8.self).baseAddress!
}
let underestimatedByteCount = bytes.underestimatedCount
Expand Down Expand Up @@ -513,7 +513,7 @@ public struct ByteBuffer {
public mutating func withUnsafeMutableReadableBytes<T>(_ body: (UnsafeMutableRawBufferPointer) throws -> T) rethrows -> T {
self._copyStorageAndRebaseIfNeeded()
let readerIndex = self.readerIndex
return try body(.init(fastRebase: self._slicedStorageBuffer[readerIndex ..< readerIndex + self.readableBytes]))
return try body(.init(rebasing: self._slicedStorageBuffer[readerIndex ..< readerIndex + self.readableBytes]))
}

/// Yields the bytes currently writable (`bytesWritable` = `capacity` - `writerIndex`). Before reading those bytes you must first
Expand All @@ -529,7 +529,7 @@ public struct ByteBuffer {
@inlinable
public mutating func withUnsafeMutableWritableBytes<T>(_ body: (UnsafeMutableRawBufferPointer) throws -> T) rethrows -> T {
self._copyStorageAndRebaseIfNeeded()
return try body(.init(fastRebase: self._slicedStorageBuffer.dropFirst(self.writerIndex)))
return try body(.init(rebasing: self._slicedStorageBuffer.dropFirst(self.writerIndex)))
}

/// This vends a pointer of the `ByteBuffer` at the `writerIndex` after ensuring that the buffer has at least `minimumWritableBytes` of writable bytes available.
Expand Down Expand Up @@ -587,7 +587,7 @@ public struct ByteBuffer {
@inlinable
public func withUnsafeReadableBytes<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T {
let readerIndex = self.readerIndex
return try body(.init(fastRebase: self._slicedStorageBuffer[readerIndex ..< readerIndex + self.readableBytes]))
return try body(.init(rebasing: self._slicedStorageBuffer[readerIndex ..< readerIndex + self.readableBytes]))
}

/// Yields a buffer pointer containing this `ByteBuffer`'s readable bytes. You may hold a pointer to those bytes
Expand All @@ -605,7 +605,7 @@ public struct ByteBuffer {
public func withUnsafeReadableBytesWithStorageManagement<T>(_ body: (UnsafeRawBufferPointer, Unmanaged<AnyObject>) throws -> T) rethrows -> T {
let storageReference: Unmanaged<AnyObject> = Unmanaged.passUnretained(self._storage)
let readerIndex = self.readerIndex
return try body(.init(fastRebase: self._slicedStorageBuffer[readerIndex ..< readerIndex + self.readableBytes]),
return try body(.init(rebasing: self._slicedStorageBuffer[readerIndex ..< readerIndex + self.readableBytes]),
storageReference)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/NIO/ByteBuffer-int.swift
Expand Up @@ -62,7 +62,7 @@ extension ByteBuffer {
return self.withUnsafeReadableBytes { ptr in
var value: T = 0
withUnsafeMutableBytes(of: &value) { valuePtr in
valuePtr.copyMemory(from: UnsafeRawBufferPointer(fastRebase: ptr[range]))
valuePtr.copyMemory(from: UnsafeRawBufferPointer(rebasing: ptr[range]))
}
return _toEndianness(value: value, endianness: endianness)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/NIO/ControlMessage.swift
Expand Up @@ -52,7 +52,7 @@ struct UnsafeControlMessageStorage: Collection {
/// Get the part of the buffer for use with a message.
public subscript(position: Int) -> UnsafeMutableRawBufferPointer {
return UnsafeMutableRawBufferPointer(
fastRebase: self.buffer[(position * self.bytesPerMessage)..<((position+1) * self.bytesPerMessage)])
rebasing: self.buffer[(position * self.bytesPerMessage)..<((position+1) * self.bytesPerMessage)])
}

var startIndex: Int { return 0 }
Expand Down Expand Up @@ -239,7 +239,7 @@ struct UnsafeOutboundControlBytes {
private mutating func appendGenericControlMessage<PayloadType>(level: CInt,
type: CInt,
payload: PayloadType) {
let writableBuffer = UnsafeMutableRawBufferPointer(fastRebase: self.controlBytes[writePosition...])
let writableBuffer = UnsafeMutableRawBufferPointer(rebasing: self.controlBytes[writePosition...])

let requiredSize = NIOBSDSocketControlMessage.space(payloadSize: MemoryLayout.stride(ofValue: payload))
precondition(writableBuffer.count >= requiredSize, "Insufficient size for cmsghdr and data")
Expand All @@ -263,7 +263,7 @@ struct UnsafeOutboundControlBytes {
if writePosition == 0 {
return UnsafeMutableRawBufferPointer(start: nil, count: 0)
}
return UnsafeMutableRawBufferPointer(fastRebase: self.controlBytes[0 ..< self.writePosition])
return UnsafeMutableRawBufferPointer(rebasing: self.controlBytes[0 ..< self.writePosition])
}

}
Expand Down
41 changes: 0 additions & 41 deletions Sources/NIO/PointerHelpers.swift

This file was deleted.

0 comments on commit b2db50b

Please sign in to comment.