@@ -25,22 +25,22 @@ internal struct _NativeSet<Element: Hashable> {
25
25
@inlinable
26
26
@inline ( __always)
27
27
internal init ( ) {
28
- self . _storage = unsafe __RawSetStorage. empty
28
+ unsafe self. _storage = __RawSetStorage. empty
29
29
}
30
30
31
31
/// Constructs a native set adopting the given storage.
32
32
@inlinable
33
33
@inline ( __always)
34
34
internal init ( _ storage: __owned __RawSetStorage) {
35
- self . _storage = unsafe storage
35
+ unsafe self. _storage = storage
36
36
}
37
37
38
38
@inlinable
39
39
internal init ( capacity: Int ) {
40
40
if capacity == 0 {
41
- self . _storage = unsafe __RawSetStorage. empty
41
+ unsafe self. _storage = __RawSetStorage. empty
42
42
} else {
43
- self . _storage = unsafe _SetStorage< Element> . allocate( capacity: capacity)
43
+ unsafe self. _storage = _SetStorage< Element> . allocate( capacity: capacity)
44
44
}
45
45
}
46
46
@@ -53,10 +53,10 @@ internal struct _NativeSet<Element: Hashable> {
53
53
@inlinable
54
54
internal init ( _ cocoa: __owned __CocoaSet, capacity: Int ) {
55
55
if capacity == 0 {
56
- self . _storage = unsafe __RawSetStorage. empty
56
+ unsafe self. _storage = __RawSetStorage. empty
57
57
} else {
58
58
_internalInvariant ( cocoa. count <= capacity)
59
- self . _storage = unsafe _SetStorage< Element> . convert( cocoa, capacity: capacity)
59
+ unsafe self. _storage = _SetStorage< Element> . convert( cocoa, capacity: capacity)
60
60
for element in cocoa {
61
61
let nativeElement = _forceBridgeFromObjectiveC ( element, Element . self)
62
62
insertNew ( nativeElement, isUnique: true )
@@ -151,10 +151,11 @@ extension _NativeSet { // Low-level lookup operations
151
151
return unsafe element. _rawHashValue ( seed: _storage. _seed)
152
152
}
153
153
154
+ @safe
154
155
@inlinable
155
156
@inline ( __always)
156
157
internal func find( _ element: Element ) -> ( bucket: Bucket , found: Bool ) {
157
- return find ( element, hashValue: self . hashValue ( for: element) )
158
+ return unsafe find( element, hashValue: self . hashValue ( for: element) )
158
159
}
159
160
160
161
/// Search for a given element, assuming it has the specified hash value.
@@ -167,10 +168,10 @@ extension _NativeSet { // Low-level lookup operations
167
168
_ element: Element ,
168
169
hashValue: Int
169
170
) -> ( bucket: Bucket , found: Bool ) {
170
- let hashTable = self . hashTable
171
+ let hashTable = unsafe self. hashTable
171
172
var bucket = unsafe hashTable. idealBucket ( forHashValue: hashValue)
172
173
while unsafe hashTable. _isOccupied ( bucket) {
173
- if uncheckedElement ( at: bucket) == element {
174
+ if unsafe uncheckedElement( at: bucket) == element {
174
175
return unsafe ( bucket, true )
175
176
}
176
177
unsafe bucket = unsafe hashTable. bucket ( wrappedAfter: bucket)
@@ -197,7 +198,7 @@ extension _NativeSet { // ensureUnique
197
198
unsafe _storage. _hashTable . clear ( )
198
199
unsafe _storage. _count = 0
199
200
}
200
- _storage = result. _storage
201
+ unsafe _storage = result. _storage
201
202
}
202
203
203
204
@inlinable
@@ -209,10 +210,10 @@ extension _NativeSet { // ensureUnique
209
210
move: false ) )
210
211
if count > 0 {
211
212
for unsafe bucket in unsafe hashTable {
212
- result. _unsafeInsertNew ( self . uncheckedElement ( at: bucket) )
213
+ unsafe result. _unsafeInsertNew ( self . uncheckedElement ( at: bucket) )
213
214
}
214
215
}
215
- _storage = result. _storage
216
+ unsafe _storage = result. _storage
216
217
}
217
218
218
219
@in linable
@@ -221,16 +222,16 @@ extension _NativeSet { // ensureUnique
221
222
unsafe _internalInvariant ( newStorage. _scale == _storage. _scale)
222
223
unsafe _internalInvariant ( newStorage. _age == _storage. _age)
223
224
unsafe _internalInvariant ( newStorage. _seed == _storage. _seed)
224
- let result = _NativeSet ( newStorage)
225
+ let result = unsafe _NativeSet( newStorage)
225
226
if count > 0 {
226
227
unsafe result. hashTable . copyContents ( of: hashTable)
227
228
unsafe result. _storage . _count = self . count
228
229
for unsafe bucket in unsafe hashTable {
229
- let element = uncheckedElement ( at: bucket)
230
- result. uncheckedInitialize ( at: bucket, to: element)
230
+ let element = unsafe uncheckedElement( at: bucket)
231
+ unsafe result. uncheckedInitialize ( at: bucket, to: element)
231
232
}
232
233
}
233
- _storage = result. _storage
234
+ unsafe _storage = result. _storage
234
235
}
235
236
236
237
/// Ensure storage of self is uniquely held and can hold at least `capacity`
@@ -347,8 +348,8 @@ extension _NativeSet: _SetBuffer {
347
348
@inlinable
348
349
@inline ( __always)
349
350
internal func element( at index: Index ) -> Element {
350
- let bucket = validatedBucket ( for: index)
351
- return uncheckedElement ( at: bucket)
351
+ let bucket = unsafe validatedBucket( for: index)
352
+ return unsafe uncheckedElement( at: bucket)
352
353
}
353
354
}
354
355
@@ -382,7 +383,7 @@ extension _NativeSet { // Insertions
382
383
// elements -- these imply that the Element type violates Hashable
383
384
// requirements. This is generally more costly than a direct insertion,
384
385
// because we'll need to compare elements in case of hash collisions.
385
- let ( bucket, found) = find ( element, hashValue: hashValue)
386
+ let ( bucket, found) = unsafe find( element, hashValue: hashValue)
386
387
guard !found else {
387
388
#if !$Embedded
388
389
ELEMENT_TYPE_OF_SET_VIOLATES_HASHABLE_REQUIREMENTS ( Element . self)
@@ -391,10 +392,10 @@ extension _NativeSet { // Insertions
391
392
#endif
392
393
}
393
394
unsafe hashTable. insert ( bucket)
394
- uncheckedInitialize ( at: bucket, to: element)
395
+ unsafe uncheckedInitialize( at: bucket, to: element)
395
396
} else {
396
397
let bucket = unsafe hashTable. insertNew ( hashValue: hashValue)
397
- uncheckedInitialize ( at: bucket, to: element)
398
+ unsafe uncheckedInitialize( at: bucket, to: element)
398
399
}
399
400
unsafe _storage. _count &+= 1
400
401
}
@@ -411,7 +412,7 @@ extension _NativeSet { // Insertions
411
412
@inlinable
412
413
internal func _unsafeInsertNew( _ element: __owned Element, at bucket: Bucket ) {
413
414
unsafe hashTable. insert ( bucket)
414
- uncheckedInitialize ( at: bucket, to: element)
415
+ unsafe uncheckedInitialize( at: bucket, to: element)
415
416
unsafe _storage. _count += 1
416
417
}
417
418
@@ -435,7 +436,7 @@ extension _NativeSet { // Insertions
435
436
}
436
437
unsafe bucket = unsafe b
437
438
}
438
- _unsafeInsertNew ( element, at: bucket)
439
+ unsafe _unsafeInsertNew( element, at: bucket)
439
440
}
440
441
441
442
@inlinable
@@ -460,10 +461,10 @@ extension _NativeSet { // Insertions
460
461
}
461
462
if found {
462
463
let old = unsafe ( _elements + bucket. offset) . move ( )
463
- uncheckedInitialize ( at: bucket, to: element)
464
+ unsafe uncheckedInitialize( at: bucket, to: element)
464
465
return old
465
466
}
466
- _unsafeInsertNew ( element, at: bucket)
467
+ unsafe _unsafeInsertNew( element, at: bucket)
467
468
return nil
468
469
}
469
470
@@ -475,10 +476,10 @@ extension _NativeSet { // Insertions
475
476
) {
476
477
let ( bucket, found) = find ( element)
477
478
if found {
478
- uncheckedAssign ( at: bucket, to: element)
479
+ unsafe uncheckedAssign( at: bucket, to: element)
479
480
} else {
480
481
_precondition ( count < capacity)
481
- _unsafeInsertNew ( element, at: bucket)
482
+ unsafe _unsafeInsertNew( element, at: bucket)
482
483
}
483
484
}
484
485
}
@@ -487,7 +488,7 @@ extension _NativeSet {
487
488
@inlinable
488
489
@inline ( __always)
489
490
func isEqual( to other: _NativeSet ) -> Bool {
490
- if self . _storage === other. _storage { return true }
491
+ if unsafe ( self . _storage === other. _storage) { return true }
491
492
if self . count != other. count { return false }
492
493
493
494
for member in self {
@@ -503,7 +504,7 @@ extension _NativeSet {
503
504
504
505
defer { _fixLifetime ( self ) }
505
506
for unsafe bucket in unsafe self. hashTable {
506
- let key = self . uncheckedElement ( at: bucket)
507
+ let key = unsafe self. uncheckedElement ( at: bucket)
507
508
let bridgedKey = _bridgeAnythingToObjectiveC ( key)
508
509
guard other. contains ( bridgedKey) else { return false }
509
510
}
@@ -516,7 +517,7 @@ extension _NativeSet: _HashTableDelegate {
516
517
@inlinable
517
518
@inline ( __always)
518
519
internal func hashValue( at bucket: Bucket ) -> Int {
519
- return hashValue ( for: uncheckedElement ( at: bucket) )
520
+ return hashValue ( for: unsafe uncheckedElement( at: bucket) )
520
521
}
521
522
522
523
@inlinable
@@ -546,15 +547,15 @@ extension _NativeSet { // Deletion
546
547
let rehashed = ensureUnique ( isUnique: isUnique, capacity: capacity)
547
548
_internalInvariant ( !rehashed)
548
549
let old = unsafe ( _elements + bucket. offset) . move ( )
549
- _delete ( at: bucket)
550
+ unsafe _delete( at: bucket)
550
551
return old
551
552
}
552
553
553
554
@usableFromInline
554
555
internal mutating func removeAll( isUnique: Bool ) {
555
556
guard isUnique else {
556
557
let scale = unsafe self. _storage . _scale
557
- _storage = unsafe _SetStorage< Element> . allocate(
558
+ unsafe _storage = _SetStorage< Element> . allocate(
558
559
scale: scale,
559
560
age: nil ,
560
561
seed: nil )
@@ -585,7 +586,7 @@ extension _NativeSet: Sequence {
585
586
@inline ( __always)
586
587
init ( _ base: __owned _NativeSet) {
587
588
self . base = base
588
- self . iterator = unsafe base. hashTable . makeIterator ( )
589
+ unsafe self. iterator = base. hashTable. makeIterator ( )
589
590
}
590
591
}
591
592
@@ -604,7 +605,7 @@ extension _NativeSet.Iterator: IteratorProtocol {
604
605
@inline ( __always)
605
606
internal mutating func next( ) -> Element ? {
606
607
guard let index = unsafe iterator. next ( ) else { return nil }
607
- return base. uncheckedElement ( at: index)
608
+ return unsafe base. uncheckedElement ( at: index)
608
609
}
609
610
}
610
611
@@ -736,7 +737,7 @@ extension _NativeSet {
736
737
}
737
738
}
738
739
unsafe _internalInvariant ( difference. count > 0 )
739
- return extractSubset ( using: difference, count: remainingCount)
740
+ return unsafe extractSubset( using: difference, count: remainingCount)
740
741
}
741
742
}
742
743
@@ -747,12 +748,12 @@ extension _NativeSet {
747
748
try unsafe _UnsafeBitset. withTemporaryBitset ( capacity: bucketCount) { bitset in
748
749
var count = 0
749
750
for unsafe bucket in unsafe hashTable {
750
- if try isIncluded ( uncheckedElement ( at: bucket) ) {
751
+ if try isIncluded ( unsafe uncheckedElement( at: bucket) ) {
751
752
unsafe bitset. uncheckedInsert ( bucket. offset)
752
753
count += 1
753
754
}
754
755
}
755
- return extractSubset ( using: bitset, count: count)
756
+ return unsafe extractSubset( using: bitset, count: count)
756
757
}
757
758
}
758
759
@@ -779,13 +780,13 @@ extension _NativeSet {
779
780
}
780
781
} else {
781
782
for unsafe bucket in unsafe hashTable {
782
- if other. find ( uncheckedElement ( at: bucket) ) . found {
783
+ if other. find ( unsafe uncheckedElement( at: bucket) ) . found {
783
784
unsafe bitset. uncheckedInsert ( bucket. offset)
784
785
count += 1
785
786
}
786
787
}
787
788
}
788
- return extractSubset ( using: bitset, count: count)
789
+ return unsafe extractSubset( using: bitset, count: count)
789
790
}
790
791
}
791
792
@@ -807,7 +808,7 @@ extension _NativeSet {
807
808
count += 1
808
809
}
809
810
}
810
- return extractSubset ( using: bitset, count: count)
811
+ return unsafe extractSubset( using: bitset, count: count)
811
812
}
812
813
}
813
814
}
0 commit comments