Skip to content

Commit

Permalink
speed up getBytes
Browse files Browse the repository at this point in the history
Motivation:

Due to https://bugs.swift.org/browse/SR-9604, ByteBuffer.getBytes
seriously regressed (factor 10x) since NIO 1.11 . This works around it
until the issue is fixed.

Modifications:

bind the memory to UInt8s to get an UnsafeBufferPointer<UInt8> rather
than an UnsafeRawBufferPointer.

Result:

- getBytes 10x faster
- make @John-Connolly happy, thanks for reporting!
  • Loading branch information
Johannes Weiss committed Jan 19, 2019
1 parent f32f283 commit 264fbe0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/NIO/ByteBuffer-aux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ extension ByteBuffer {
}

return self.withVeryUnsafeBytes { ptr in
Array<UInt8>(ptr[index..<(index+length)])
// this is not technically 100% but we need to work around https://bugs.swift.org/browse/SR-9604
Array<UInt8>(UnsafeRawBufferPointer(rebasing: ptr[index..<(index+length)]).bindMemory(to: UInt8.self))
}
}

Expand Down

0 comments on commit 264fbe0

Please # to comment.