Skip to content

Commit a764480

Browse files
authored
Merge pull request #2151 from compnerd/inline-inline-inline
2 parents 5321f69 + 51aff9b commit a764480

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Foundation/Data.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ internal func __NSDataIsCompact(_ data: NSData) -> Bool {
6161

6262
#endif
6363

64+
#if os(Windows)
65+
@usableFromInline @discardableResult
66+
internal func __withStackOrHeapBuffer(_ size: Int, _ block: (UnsafeMutablePointer<_ConditionalAllocationBuffer>) -> Void) -> Bool {
67+
return _withStackOrHeapBuffer(size, block)
68+
}
69+
#else
70+
@inlinable @inline(__always) @discardableResult
71+
internal func __withStackOrHeapBuffer(_ size: Int, _ block: (UnsafeMutablePointer<_ConditionalAllocationBuffer>) -> Void) -> Bool {
72+
return _withStackOrHeapBuffer(size, block)
73+
}
74+
#endif
75+
6476
// Underlying storage representation for medium and large data.
6577
// Inlinability strategy: methods from here should not inline into InlineSlice or LargeSlice unless trivial.
6678
// NOTE: older overlays called this class _DataStorage. The two must
@@ -2048,7 +2060,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
20482060
}
20492061

20502062
}
2051-
2063+
20522064
// slightly faster paths for common sequences
20532065
@inlinable // This is @inlinable as an important generic funnel point, despite being a non-trivial initializer.
20542066
public init<S: Sequence>(_ elements: S) where S.Element == UInt8 {
@@ -2072,7 +2084,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
20722084

20732085
// Copy as much as we can in one shot from the sequence.
20742086
let underestimatedCount = Swift.max(elements.underestimatedCount, 1)
2075-
_withStackOrHeapBuffer(underestimatedCount) { (buffer) in
2087+
__withStackOrHeapBuffer(underestimatedCount) { (buffer) in
20762088
// In order to copy from the sequence, we have to bind the buffer to UInt8.
20772089
// This is safe since we'll copy out of this buffer as raw memory later.
20782090
let capacity = buffer.pointee.capacity
@@ -2365,7 +2377,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
23652377
// The sequence is really not contiguous.
23662378
// Copy as much as we can in one shot.
23672379
let underestimatedCount = Swift.max(elements.underestimatedCount, 1)
2368-
_withStackOrHeapBuffer(underestimatedCount) { (buffer) in
2380+
__withStackOrHeapBuffer(underestimatedCount) { (buffer) in
23692381
// In order to copy from the sequence, we have to bind the temporary buffer to `UInt8`.
23702382
// This is safe since we're the only owners of the buffer and we copy out as raw memory below anyway.
23712383
let capacity = buffer.pointee.capacity
@@ -2444,7 +2456,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
24442456
@inlinable // This is @inlinable as generic and reasonably small.
24452457
public mutating func replaceSubrange<ByteCollection : Collection>(_ subrange: Range<Index>, with newElements: ByteCollection) where ByteCollection.Iterator.Element == Data.Iterator.Element {
24462458
let totalCount = Int(newElements.count)
2447-
_withStackOrHeapBuffer(totalCount) { conditionalBuffer in
2459+
__withStackOrHeapBuffer(totalCount) { conditionalBuffer in
24482460
let buffer = UnsafeMutableBufferPointer(start: conditionalBuffer.pointee.memory.assumingMemoryBound(to: UInt8.self), count: totalCount)
24492461
var (iterator, index) = newElements._copyContents(initializing: buffer)
24502462
while let byte = iterator.next() {

0 commit comments

Comments
 (0)