@@ -189,10 +189,8 @@ public struct Deque<Element>: RandomAccessCollection, MutableCollection {
189
189
return _storage. header. index ( before: i)
190
190
}
191
191
192
- @inlinable
193
- public func formIndex( _ i: inout Index , offsetBy distance: Int ) {
194
- _storage. header. formIndex ( & i, offsetBy: distance)
195
- }
192
+ // Note: formIndex(_:offsetBy:) is not actually declared in any collection protocol, it's
193
+ // instead provided as an extension using index(_:offsetBy:), so we can skip it.
196
194
197
195
@inlinable
198
196
public func index( _ i: Index , offsetBy distance: Int ) -> Index {
@@ -854,11 +852,6 @@ public struct Deque<Element>: RandomAccessCollection, MutableCollection {
854
852
return _header. index ( before: i)
855
853
}
856
854
857
- @inlinable
858
- public func formIndex( _ i: inout Index , offsetBy distance: Int ) {
859
- _header. formIndex ( & i, offsetBy: distance)
860
- }
861
-
862
855
@inlinable
863
856
public func index( _ i: Index , offsetBy distance: Int ) -> Index {
864
857
return _header. index ( i, offsetBy: distance)
@@ -1267,36 +1260,31 @@ internal struct _DequeHeader {
1267
1260
}
1268
1261
1269
1262
@inlinable
1270
- func formIndex( _ i: inout Index , offsetBy distance: Int ) {
1263
+ func index( _ i: Index , offsetBy distance: Int ) -> Index {
1264
+ var rawValue = i. _rawValue
1271
1265
if distance > 0 {
1272
- let wasHead = i . _rawValue < Index . _tailFlag
1273
- i . _rawValue += UInt ( bitPattern: distance)
1274
- if wasHead && i . _rawValue >= UInt ( bitPattern: capacity) && tailCount > 0 {
1266
+ let wasHead = rawValue < Index . _tailFlag
1267
+ rawValue += UInt ( bitPattern: distance)
1268
+ if wasHead && rawValue >= UInt ( bitPattern: capacity) && tailCount > 0 {
1275
1269
// Wrap around
1276
- i . _rawValue = ( i . _rawValue &- UInt ( bitPattern: capacity) ) | Index . _tailFlag
1270
+ rawValue = ( rawValue &- UInt ( bitPattern: capacity) ) | Index . _tailFlag
1277
1271
}
1278
1272
} else if distance < 0 {
1279
- if i . _rawValue >= Index . _tailFlag {
1280
- i . _rawValue &+= UInt ( bitPattern: distance) // equivalent to signed addition
1281
- if i . _rawValue < Index . _tailFlag {
1273
+ if rawValue >= Index . _tailFlag {
1274
+ rawValue &+= UInt ( bitPattern: distance) // equivalent to signed addition
1275
+ if rawValue < Index . _tailFlag {
1282
1276
// We subtracted past the beginning of the tail
1283
- let result = UInt ( bitPattern: capacity) . subtractingReportingOverflow ( Index . _tailFlag &- i . _rawValue )
1277
+ let result = UInt ( bitPattern: capacity) . subtractingReportingOverflow ( Index . _tailFlag &- rawValue )
1284
1278
precondition ( !result. overflow, " Attempted to create invalid index " ) // Report better error on overflow
1285
- i . _rawValue = result. partialValue
1279
+ rawValue = result. partialValue
1286
1280
}
1287
1281
} else {
1288
- let newValue = i . _rawValue &+ UInt ( bitPattern: distance) // equivalent to signed addition
1289
- precondition ( newValue < i . _rawValue , " Attempted to create invalid index " ) // Report error on overflow
1290
- i . _rawValue = newValue
1282
+ let newValue = rawValue &+ UInt ( bitPattern: distance) // equivalent to signed addition
1283
+ precondition ( newValue < rawValue , " Attempted to create invalid index " ) // Report error on overflow
1284
+ rawValue = newValue
1291
1285
}
1292
1286
}
1293
- }
1294
-
1295
- @inlinable
1296
- func index( _ i: Index , offsetBy distance: Int ) -> Index {
1297
- var i = i
1298
- formIndex ( & i, offsetBy: distance)
1299
- return i
1287
+ return Index ( _rawValue: rawValue)
1300
1288
}
1301
1289
1302
1290
@inlinable
0 commit comments