@@ -40,22 +40,6 @@ struct _StringGuts {
40
40
public // FIXME for testing only
41
41
var _otherBits : UInt // (Mostly) count or inline storage
42
42
43
- #if arch(i386) || arch(arm)
44
- public // FIXME for testing only
45
- var _extraBits : UInt // Start address or inline storage
46
- #endif
47
-
48
- #if arch(i386) || arch(arm)
49
- @_inlineable
50
- @inline ( __always)
51
- public
52
- init ( object: _StringObject , otherBits: UInt , extraBits: UInt ) {
53
- self . _object = object
54
- self . _otherBits = otherBits
55
- self . _extraBits = extraBits
56
- _invariantCheck ( )
57
- }
58
- #else
59
43
@_inlineable
60
44
@inline ( __always)
61
45
public
@@ -64,36 +48,22 @@ struct _StringGuts {
64
48
self . _otherBits = otherBits
65
49
_invariantCheck ( )
66
50
}
67
- #endif
68
51
69
- public typealias _RawBitPattern = ( UInt64 , UInt64 )
52
+ public typealias _RawBitPattern = ( _StringObject . _RawBitPattern , UInt )
70
53
71
54
@_versioned
72
55
@_inlineable
73
56
internal var rawBits : _RawBitPattern {
74
57
@inline ( __always)
75
58
get {
76
- #if arch(i386) || arch(arm)
77
- return ( _object. rawBits,
78
- UInt64 ( truncatingIfNeeded: _extraBits) &<< 32 |
79
- UInt64 ( truncatingIfNeeded: _otherBits) )
80
- #else
81
- return ( _object. rawBits, UInt64 ( truncatingIfNeeded: _otherBits) )
82
- #endif
59
+ return ( _object. rawBits, _otherBits)
83
60
}
84
61
}
85
62
86
63
init ( rawBits: _RawBitPattern ) {
87
- #if arch(i386) || arch(arm)
88
- self . init (
89
- object: _StringObject ( rawBits: rawBits. 0 ) ,
90
- otherBits: UInt ( truncatingIfNeeded: rawBits. 1 ) ,
91
- extraBits: UInt ( truncatingIfNeeded: rawBits. 1 &>> 32 ) )
92
- #else
93
64
self . init (
94
65
object: _StringObject ( rawBits: rawBits. 0 ) ,
95
- otherBits: UInt ( rawBits. 1 ) )
96
- #endif
66
+ otherBits: rawBits. 1 )
97
67
}
98
68
}
99
69
@@ -103,25 +73,6 @@ extension _StringGuts {
103
73
internal func _invariantCheck( ) {
104
74
#if INTERNAL_CHECKS_ENABLED
105
75
_object. _invariantCheck ( )
106
- #if arch(i386) || arch(arm)
107
- if _object. isContiguous {
108
- _sanityCheck ( _extraBits != 0 ) // TODO: in ABI's address space
109
- } else {
110
- _sanityCheck ( _extraBits == 0 )
111
- }
112
- if _object. isNative {
113
- _sanityCheck ( UInt ( _object. nativeRawStorage. count) == self . _otherBits)
114
- _sanityCheck (
115
- UInt ( bitPattern: _object. nativeRawStorage. rawStart) == self . _extraBits)
116
- } else if _object. isUnmanaged {
117
- } else if _object. isCocoa {
118
- _sanityCheck ( _otherBits != 0 )
119
- } else if _object. isSmall {
120
- fatalError ( " Small strings aren't supported yet " )
121
- } else {
122
- fatalError ( " Unimplemented string form " )
123
- }
124
- #else // 64-bit
125
76
if _object. isNative {
126
77
_sanityCheck ( UInt ( _object. nativeRawStorage. count) == self . _otherBits)
127
78
} else if _object. isUnmanaged {
@@ -135,7 +86,6 @@ extension _StringGuts {
135
86
} else {
136
87
fatalError ( " Unimplemented string form " )
137
88
}
138
- #endif // arch(i386) || arch(arm)
139
89
#endif // INTERNAL_CHECKS_ENABLED
140
90
}
141
91
@@ -158,7 +108,6 @@ extension _StringGuts {
158
108
var bitPattern = _object. referenceBits
159
109
return _isUnique_native ( & bitPattern)
160
110
}
161
-
162
111
}
163
112
164
113
extension _StringGuts {
@@ -211,12 +160,8 @@ extension _StringGuts {
211
160
@_versioned
212
161
@_inlineable
213
162
internal
214
- var _isEmptyLiteral : Bool {
215
- #if arch(i386) || arch(arm)
216
- return _extraBits == UInt ( bitPattern: _emptyStringBase)
217
- #else
218
- return _object. isEmptyLiteral
219
- #endif
163
+ var _isEmptySingleton : Bool {
164
+ return _object. isEmptySingleton
220
165
}
221
166
222
167
@_inlineable
@@ -246,16 +191,9 @@ extension _StringGuts {
246
191
init < CodeUnit> ( _ storage: _SwiftStringStorage < CodeUnit > )
247
192
where CodeUnit : FixedWidthInteger & UnsignedInteger {
248
193
_sanityCheck ( storage. count >= 0 )
249
- #if arch(i386) || arch(arm)
250
- self . init (
251
- object: _StringObject ( storage) ,
252
- otherBits: UInt ( bitPattern: storage. count) ,
253
- extraBits: UInt ( bitPattern: storage. rawStart) )
254
- #else
255
194
self . init (
256
195
object: _StringObject ( storage) ,
257
196
otherBits: UInt ( bitPattern: storage. count) )
258
- #endif
259
197
}
260
198
}
261
199
@@ -264,14 +202,7 @@ extension _StringGuts {
264
202
@inline ( __always)
265
203
public // @testable
266
204
init ( ) {
267
- #if arch(i386) || arch(arm)
268
- self . init (
269
- object: _StringObject ( ) ,
270
- otherBits: 0 ,
271
- extraBits: UInt ( bitPattern: _emptyStringBase) )
272
- #else
273
205
self . init ( object: _StringObject ( ) , otherBits: 0 )
274
- #endif
275
206
_invariantCheck ( )
276
207
}
277
208
}
@@ -340,22 +271,12 @@ extension _StringGuts {
340
271
self . init ( )
341
272
return
342
273
}
343
- #if arch(i386) || arch(arm)
344
- self . init (
345
- object: _StringObject (
346
- cocoaObject: s,
347
- isSingleByte: isSingleByte,
348
- isContiguous: start != nil ) ,
349
- otherBits: UInt ( bitPattern: count) ,
350
- extraBits: UInt ( bitPattern: start) )
351
- #else
352
274
self . init (
353
275
object: _StringObject (
354
276
cocoaObject: s,
355
277
isSingleByte: isSingleByte,
356
278
isContiguous: start != nil ) ,
357
279
otherBits: UInt ( bitPattern: start) )
358
- #endif
359
280
if start == nil {
360
281
_sanityCheck ( _object. isOpaque)
361
282
} else {
@@ -392,11 +313,7 @@ extension _StringGuts {
392
313
internal var _unmanagedRawStart : UnsafeRawPointer {
393
314
@inline ( __always) get {
394
315
_sanityCheck ( _object. isUnmanaged)
395
- #if arch(i386) || arch(arm)
396
- return Builtin . reinterpretCast ( _extraBits)
397
- #else
398
316
return _object. asUnmanagedRawStart
399
- #endif
400
317
}
401
318
}
402
319
@@ -430,16 +347,9 @@ extension _StringGuts {
430
347
init < CodeUnit> ( _ s: _UnmanagedString < CodeUnit > )
431
348
where CodeUnit : FixedWidthInteger & UnsignedInteger {
432
349
_sanityCheck ( s. count >= 0 )
433
- #if arch(i386) || arch(arm)
434
- self . init (
435
- object: _StringObject ( unmanagedWithBitWidth: CodeUnit . bitWidth) ,
436
- otherBits: UInt ( bitPattern: s. count) ,
437
- extraBits: UInt ( bitPattern: s. rawStart) )
438
- #else
439
350
self . init (
440
351
object: _StringObject ( unmanaged: s. start) ,
441
352
otherBits: UInt ( bitPattern: s. count) )
442
- #endif
443
353
_sanityCheck ( _object. isUnmanaged)
444
354
_sanityCheck ( _unmanagedRawStart == s. rawStart)
445
355
_sanityCheck ( _unmanagedCount == s. count)
@@ -455,24 +365,34 @@ extension _StringGuts {
455
365
@_versioned
456
366
@_inlineable
457
367
internal var _taggedCocoaCount : Int {
458
- _sanityCheck ( _object. isSmall)
459
- return Int ( truncatingIfNeeded: _object. payloadBits)
368
+ @inline ( __always) get {
369
+ #if arch(i386) || arch(arm)
370
+ _sanityCheckFailure ( " Tagged Cocoa objects aren't supported on 32-bit platforms " )
371
+ #else
372
+ _sanityCheck ( _object. isSmall)
373
+ return Int ( truncatingIfNeeded: _object. payloadBits)
374
+ #endif
375
+ }
460
376
}
461
377
462
378
@_versioned
463
379
@_inlineable
464
380
internal var _taggedCocoaObject : _CocoaString {
465
381
@inline ( __always) get {
382
+ #if arch(i386) || arch(arm)
383
+ _sanityCheckFailure ( " Tagged Cocoa objects aren't supported on 32-bit platforms " )
384
+ #else
466
385
_sanityCheck ( _object. isSmall)
467
386
return Builtin . reinterpretCast ( _otherBits)
387
+ #endif
468
388
}
469
389
}
470
390
471
391
@_versioned
472
392
@inline ( never) // Hide CF dependency
473
393
internal init ( _taggedCocoaObject object: _CocoaString ) {
474
394
#if arch(i386) || arch(arm)
475
- _sanityCheckFailure ( " 32-bit platforms don 't have tagged Cocoa objects " )
395
+ _sanityCheckFailure ( " Tagged Cocoa objects aren 't supported on 32-bit platforms " )
476
396
#else
477
397
_sanityCheck ( _isObjCTaggedPointer ( object) )
478
398
let count = _stdlib_binary_CFStringGetLength ( object)
@@ -494,14 +414,6 @@ extension _StringGuts {
494
414
@effects ( readonly)
495
415
get {
496
416
_sanityCheck ( _object. isContiguousASCII)
497
- #if arch(i386) || arch(arm)
498
- _sanityCheck ( self . _extraBits != 0 )
499
- let start = UnsafePointer < UInt8 > ( bitPattern: _extraBits)
500
- let count = Int ( bitPattern: _otherBits)
501
- return _UnmanagedASCIIString (
502
- start: start. _unsafelyUnwrappedUnchecked,
503
- count: count)
504
- #else
505
417
if _object. isUnmanaged {
506
418
return _asUnmanaged ( )
507
419
} else if _object. isNative {
@@ -514,7 +426,6 @@ extension _StringGuts {
514
426
Builtin . unreachable ( )
515
427
#endif
516
428
}
517
- #endif // arch(i386) || arch(arm)
518
429
}
519
430
}
520
431
@@ -525,14 +436,6 @@ extension _StringGuts {
525
436
@effects ( readonly)
526
437
get {
527
438
_sanityCheck ( _object. isContiguousUTF16)
528
- #if arch(i386) || arch(arm)
529
- _sanityCheck ( _extraBits != 0 )
530
- let start = UnsafePointer < UTF16 . CodeUnit > ( bitPattern: _extraBits)
531
- let count = Int ( bitPattern: _otherBits)
532
- return _UnmanagedUTF16String (
533
- start: start. _unsafelyUnwrappedUnchecked,
534
- count: count)
535
- #else
536
439
if _object. isUnmanaged {
537
440
return _asUnmanaged ( )
538
441
} else if _object. isNative {
@@ -545,7 +448,6 @@ extension _StringGuts {
545
448
Builtin . unreachable ( )
546
449
#endif
547
450
}
548
- #endif // arch(i386) || arch(arm)
549
451
}
550
452
}
551
453
}
@@ -1138,7 +1040,7 @@ extension _StringGuts {
1138
1040
@_inlineable
1139
1041
public // TODO(StringGuts): for testing only
1140
1042
mutating func append( _ other: _StringGuts ) {
1141
- if _isEmptyLiteral {
1043
+ if _isEmptySingleton {
1142
1044
self = other
1143
1045
return
1144
1046
}
@@ -1157,7 +1059,7 @@ extension _StringGuts {
1157
1059
mutating func append( _ other: _StringGuts , range: Range < Int > ) {
1158
1060
_sanityCheck ( range. lowerBound >= 0 && range. upperBound <= other. count)
1159
1061
guard range. count > 0 else { return }
1160
- if _isEmptyLiteral && range. count == other. count {
1062
+ if _isEmptySingleton && range. count == other. count {
1161
1063
self = other
1162
1064
return
1163
1065
}
0 commit comments