mirror of
https://github.com/apple/swift-nio
synced 2026-11-27 05:04:22 +00:00
fix optimiser problem triggered in BB.set(staticString:) (#354)
Motivation:
There's a presumed optimiser bug which will trigger an allocation when
using `self` within `staticString.withUTF8Buffer { ... }` which makes it
cause an extra allocation.
Modifications:
use StaticString.utf8Start instead of withUTF8Buffer
Result:
less allocations
This commit is contained in:
1 parent
91ada57582
commit
89e5574bb4
1 file changed
+3
-3
@@ -73,9 +73,9 @@ extension ByteBuffer {
|
||||
/// - index: The index for the first serialized byte.
|
||||
/// - returns: The number of bytes written.
|
||||
public mutating func set(staticString string: StaticString, at index: Int) -> Int {
|
||||
return string.withUTF8Buffer { ptr -> Int in
|
||||
self.set(bytes: UnsafeRawBufferPointer(ptr), at: index)
|
||||
}
|
||||
// please do not replace the code below with code that uses `string.withUTF8Buffer { ... }` (see SR-7541)
|
||||
return self.set(bytes: UnsafeRawBufferPointer(start: string.utf8Start,
|
||||
count: string.utf8CodeUnitCount), at: index)
|
||||
}
|
||||
|
||||
// MARK: String APIs
|
||||
|
||||
Reference in new issue
Block a user