@@ -475,7 +475,7 @@ public struct Set<Element : Hashable> :
475
475
public init(minimumCapacity: Int) {
476
476
_variantBuffer =
477
477
_VariantBuffer.native(
478
- _NativeBuffer.create (minimumCapacity: minimumCapacity))
478
+ _NativeBuffer(minimumCapacity: minimumCapacity))
479
479
}
480
480
481
481
/// Private initializer.
@@ -1667,7 +1667,7 @@ public struct Dictionary<Key : Hashable, Value> :
1667
1667
/// allocate buffer for in the new dictionary.
1668
1668
public init(minimumCapacity: Int) {
1669
1669
_variantBuffer =
1670
- .native(_NativeBuffer.create (minimumCapacity: minimumCapacity))
1670
+ .native(_NativeBuffer(minimumCapacity: minimumCapacity))
1671
1671
}
1672
1672
1673
1673
internal init(_nativeBuffer: _NativeDictionaryBuffer<Key, Value>) {
@@ -2534,6 +2534,8 @@ internal class _RawNative${Self}Storage:
2534
2534
return storage
2535
2535
}()
2536
2536
2537
+ // This type is made with allocWithTailElems, so no init is ever called.
2538
+ // But we still need to have an init to satisfy the compiler.
2537
2539
internal init(_doNotCallMe: ()) {
2538
2540
_sanityCheckFailure("Only create this by using the `empty` singleton")
2539
2541
}
@@ -2664,8 +2666,10 @@ internal class _TypedNative${Self}Storage<${TypeParameters}> :
2664
2666
_fixLifetime(self)
2665
2667
}
2666
2668
2669
+ // This type is made with allocWithTailElems, so no init is ever called.
2670
+ // But we still need to have an init to satisfy the compiler.
2667
2671
override internal init(_doNotCallMe: ()) {
2668
- _sanityCheckFailure("Only create this by calling Buffer.createUnhashable ")
2672
+ _sanityCheckFailure("Only create this by calling Buffer's inits ")
2669
2673
}
2670
2674
2671
2675
#if _runtime(_ObjC)
@@ -2696,8 +2700,10 @@ final internal class _HashableTypedNative${Self}Storage<${TypeParametersDecl}> :
2696
2700
internal typealias FullContainer = ${Self}<${TypeParameters}>
2697
2701
internal typealias Buffer = _Native${Self}Buffer<${TypeParameters}>
2698
2702
2703
+ // This type is made with allocWithTailElems, so no init is ever called.
2704
+ // But we still need to have an init to satisfy the compiler.
2699
2705
override internal init(_doNotCallMe: ()) {
2700
- _sanityCheckFailure("Only create this by calling Buffer.create ")
2706
+ _sanityCheckFailure("Only create this by calling Buffer's inits' ")
2701
2707
}
2702
2708
2703
2709
@@ -2867,8 +2873,8 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
2867
2873
internal var _storage: RawStorage
2868
2874
2869
2875
/// Creates a Buffer with a storage that is typed, but doesn't understand
2870
- /// Hashing. Mostly for bridging; prefer `create (capacity:)`.
2871
- internal static func createUnhashable (capacity: Int) -> Buffer {
2876
+ /// Hashing. Mostly for bridging; prefer `init (capacity:)`.
2877
+ internal init (capacity: Int, unhashable: ()) {
2872
2878
let numWordsForBitmap = _UnsafeBitMap.sizeInWords(forSizeInBits: capacity)
2873
2879
%if Self == 'Dictionary':
2874
2880
let storage = Builtin.allocWithTailElems_3(TypedStorage.self,
@@ -2880,31 +2886,29 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
2880
2886
numWordsForBitmap._builtinWordValue, UInt.self,
2881
2887
capacity._builtinWordValue, Key.self)
2882
2888
%end
2883
- return create (capacity: capacity, storage: storage)
2889
+ self.init (capacity: capacity, storage: storage)
2884
2890
}
2885
2891
2886
2892
/// Given a capacity and uninitialized RawStorage, completes the
2887
2893
/// initialization and returns a Buffer.
2888
- internal static func create (capacity: Int, storage: RawStorage) -> Buffer {
2894
+ internal init (capacity: Int, storage: RawStorage) {
2889
2895
// We can initialize by assignment because _HashedContainerBufferHeader
2890
2896
// is a trivial type, i.e. contains no references.
2891
2897
storage._body = BufferHeader(capacity: capacity)
2892
2898
2893
- var buffer = Buffer (_storage: storage)
2899
+ self.init (_storage: storage)
2894
2900
2895
2901
let initializedEntries = _UnsafeBitMap(
2896
- storage: buffer. _initializedHashtableEntriesBitMapBuffer,
2902
+ storage: _initializedHashtableEntriesBitMapBuffer,
2897
2903
bitCount: capacity)
2898
2904
initializedEntries.initializeToZero()
2899
2905
2900
2906
// Initialize header
2901
- buffer. _body.initializedEntries = initializedEntries
2902
- buffer. _body.keys = UnsafeMutableRawPointer(buffer. _keys)
2907
+ _body.initializedEntries = initializedEntries
2908
+ _body.keys = UnsafeMutableRawPointer(_keys)
2903
2909
%if Self == 'Dictionary':
2904
- buffer. _body.values = UnsafeMutableRawPointer(buffer. _values)
2910
+ _body.values = UnsafeMutableRawPointer(_values)
2905
2911
%end
2906
-
2907
- return buffer
2908
2912
}
2909
2913
2910
2914
/// A convenience forwarding the _storage's body
@@ -3161,19 +3165,19 @@ extension _Native${Self}Buffer
3161
3165
internal typealias SequenceElement = ${Sequence}
3162
3166
3163
3167
@inline(__always)
3164
- internal static func create (minimumCapacity: Int) -> Buffer {
3168
+ internal init (minimumCapacity: Int) {
3165
3169
// Make sure there's a representable power of 2 >= minimumCapacity
3166
3170
_sanityCheck(minimumCapacity <= (Int.max >> 1) + 1)
3167
3171
var capacity = 2
3168
3172
while capacity < minimumCapacity {
3169
3173
capacity <<= 1
3170
3174
}
3171
- return create (capacity: capacity)
3175
+ self.init (capacity: capacity)
3172
3176
}
3173
3177
3174
3178
/// Create a buffer instance with room for at least 'capacity'
3175
3179
/// entries and all entries marked invalid.
3176
- internal static func create (capacity: Int) -> Buffer {
3180
+ internal init (capacity: Int) {
3177
3181
let numWordsForBitmap = _UnsafeBitMap.sizeInWords(forSizeInBits: capacity)
3178
3182
%if Self == 'Dictionary':
3179
3183
let storage = Builtin.allocWithTailElems_3(HashTypedStorage.self,
@@ -3185,7 +3189,7 @@ extension _Native${Self}Buffer
3185
3189
numWordsForBitmap._builtinWordValue, UInt.self,
3186
3190
capacity._builtinWordValue, Key.self)
3187
3191
%end
3188
- return create (capacity: capacity, storage: storage)
3192
+ self.init (capacity: capacity, storage: storage)
3189
3193
}
3190
3194
3191
3195
#if _runtime(_ObjC)
@@ -3395,7 +3399,7 @@ extension _Native${Self}Buffer
3395
3399
Buffer.minimumCapacity(
3396
3400
minimumCount: elements.count,
3397
3401
maxLoadFactorInverse: _hashContainerDefaultMaxLoadFactorInverse)
3398
- var nativeBuffer = Buffer.create (minimumCapacity: requiredCapacity)
3402
+ var nativeBuffer = Buffer(minimumCapacity: requiredCapacity)
3399
3403
3400
3404
%if Self == 'Set':
3401
3405
@@ -3517,7 +3521,7 @@ final internal class _SwiftDeferredNS${Self}<${TypeParametersDecl}>
3517
3521
%end
3518
3522
3519
3523
internal init(minimumCapacity: Int = 2) {
3520
- nativeBuffer = NativeBuffer.create (minimumCapacity: minimumCapacity)
3524
+ nativeBuffer = NativeBuffer(minimumCapacity: minimumCapacity)
3521
3525
super.init()
3522
3526
}
3523
3527
@@ -3646,8 +3650,7 @@ final internal class _SwiftDeferredNS${Self}<${TypeParametersDecl}>
3646
3650
}
3647
3651
3648
3652
// Create buffer for bridged data.
3649
- let bridged = BridgedBuffer.createUnhashable(
3650
- capacity: nativeBuffer.capacity)
3653
+ let bridged = BridgedBuffer(capacity: nativeBuffer.capacity, unhashable: ())
3651
3654
3652
3655
// Bridge everything.
3653
3656
for i in 0..<nativeBuffer.capacity {
@@ -4014,7 +4017,7 @@ internal enum _Variant${Self}Buffer<${TypeParametersDecl}> : _HashBuffer {
4014
4017
}
4015
4018
4016
4019
let oldNativeBuffer = asNative
4017
- var newNativeBuffer = NativeBuffer.create (minimumCapacity: minimumCapacity)
4020
+ var newNativeBuffer = NativeBuffer(minimumCapacity: minimumCapacity)
4018
4021
let newCapacity = newNativeBuffer.capacity
4019
4022
for i in 0..<oldCapacity {
4020
4023
if oldNativeBuffer.isInitializedEntry(at: i) {
@@ -4047,7 +4050,7 @@ internal enum _Variant${Self}Buffer<${TypeParametersDecl}> : _HashBuffer {
4047
4050
case .cocoa(let cocoaBuffer):
4048
4051
#if _runtime(_ObjC)
4049
4052
let cocoa${Self} = cocoaBuffer.cocoa${Self}
4050
- var newNativeBuffer = NativeBuffer.create (minimumCapacity: minimumCapacity)
4053
+ var newNativeBuffer = NativeBuffer(minimumCapacity: minimumCapacity)
4051
4054
let oldCocoaIterator = _Cocoa${Self}Iterator(cocoa${Self})
4052
4055
%if Self == 'Set':
4053
4056
while let key = oldCocoaIterator.next() {
@@ -4572,7 +4575,7 @@ internal enum _Variant${Self}Buffer<${TypeParametersDecl}> : _HashBuffer {
4572
4575
}
4573
4576
4574
4577
if !keepCapacity {
4575
- self = .native(NativeBuffer.create (minimumCapacity: 2))
4578
+ self = .native(NativeBuffer(minimumCapacity: 2))
4576
4579
return
4577
4580
}
4578
4581
@@ -4586,7 +4589,7 @@ internal enum _Variant${Self}Buffer<${TypeParametersDecl}> : _HashBuffer {
4586
4589
nativeRemoveAll()
4587
4590
case .cocoa(let cocoaBuffer):
4588
4591
#if _runtime(_ObjC)
4589
- self = .native(NativeBuffer.create (minimumCapacity: cocoaBuffer.count))
4592
+ self = .native(NativeBuffer(minimumCapacity: cocoaBuffer.count))
4590
4593
#else
4591
4594
_sanityCheckFailure("internal error: unexpected cocoa ${Self}")
4592
4595
#endif
0 commit comments