@@ -430,14 +430,15 @@ extension _StringGuts {
430
430
}
431
431
432
432
internal func getAssociatedStorage( ) -> __StringStorage ? {
433
+ _internalInvariant ( _object. hasObjCBridgeableObject)
433
434
let getter = unsafe unsafeBitCast(
434
435
getGetAssociatedObjectPtr ( ) ,
435
436
to: ( @convention( c) (
436
437
AnyObject,
437
438
UnsafeRawPointer
438
439
) - > UnsafeRawPointer? ) . self
439
440
)
440
- _precondition ( _object . hasObjCBridgeableObject )
441
+
441
442
if let assocPtr = unsafe getter(
442
443
_object. objCBridgeableObject,
443
444
Self . associationKey
@@ -450,6 +451,7 @@ extension _StringGuts {
450
451
}
451
452
452
453
internal func setAssociatedStorage( _ storage: __StringStorage ) {
454
+ _internalInvariant ( _object. hasObjCBridgeableObject)
453
455
let setter = unsafe unsafeBitCast(
454
456
getSetAssociatedObjectPtr ( ) ,
455
457
to: ( @convention( c) (
@@ -469,7 +471,7 @@ extension _StringGuts {
469
471
}
470
472
471
473
internal func getOrAllocateAssociatedStorage( ) -> __StringStorage {
472
- _precondition ( _object. hasObjCBridgeableObject)
474
+ _internalInvariant ( _object. hasObjCBridgeableObject)
473
475
let unwrapped : __StringStorage
474
476
// libobjc already provides the necessary memory barriers for
475
477
// double checked locking to be safe, per comments on
@@ -483,8 +485,10 @@ extension _StringGuts {
483
485
unwrapped = storage
484
486
} else {
485
487
var contents = String . UnicodeScalarView ( )
486
- // always reserve a size larger than a small string
487
- contents. reserveCapacity ( Swift . max ( _SmallString. capacity + 1 , 1 + count + count >> 1 ) )
488
+ // always reserve a capacity larger than a small string
489
+ contents. reserveCapacity (
490
+ Swift . max ( _SmallString. capacity + 1 , count + count >> 1 )
491
+ )
488
492
for c in String . UnicodeScalarView ( self ) {
489
493
contents. append ( c)
490
494
}
0 commit comments