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:
Johannes Weiß authored and Norman Maurer committed 2018-04-26 15:41:49 +02:00
1 parent 91ada57582
commit 89e5574bb4
1 file changed
+3 -3
+3 -3
View File
@@ -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