@@ -99,7 +99,8 @@ extension Span where Element: ~Copyable {
99
99
public init (
100
100
_unsafeElements buffer: borrowing UnsafeBufferPointer < Element >
101
101
) {
102
- let baseAddress = buffer. baseAddress //FIXME: rdar://138665760
102
+ //FIXME: Workaround for https://github.com/swiftlang/swift/issues/77235
103
+ let baseAddress = buffer. baseAddress
103
104
_precondition (
104
105
( ( Int ( bitPattern: baseAddress) &
105
106
( MemoryLayout < Element > . alignment &- 1 ) ) == 0 ) ,
@@ -201,7 +202,8 @@ extension Span where Element: BitwiseCopyable {
201
202
public init (
202
203
_unsafeBytes buffer: borrowing UnsafeRawBufferPointer
203
204
) {
204
- let baseAddress = buffer. baseAddress //FIXME: rdar://138665760
205
+ //FIXME: Workaround for https://github.com/swiftlang/swift/issues/77235
206
+ let baseAddress = buffer. baseAddress
205
207
_precondition (
206
208
( ( Int ( bitPattern: baseAddress) &
207
209
( MemoryLayout < Element > . alignment &- 1 ) ) == 0 ) ,
@@ -313,87 +315,6 @@ extension Span where Element: BitwiseCopyable {
313
315
}
314
316
}
315
317
316
- @available ( SwiftStdlib 6 . 1 , * )
317
- extension Span where Element: Equatable {
318
-
319
- /// Returns a Boolean value indicating whether this and another span
320
- /// contain equal elements in the same order.
321
- ///
322
- /// - Parameters:
323
- /// - other: A span to compare to this one.
324
- /// - Returns: `true` if this sequence and `other` contain equivalent items,
325
- /// using `areEquivalent` as the equivalence test; otherwise, `false.`
326
- ///
327
- /// - Complexity: O(*m*), where *m* is the lesser of the length of the
328
- /// sequence and the length of `other`.
329
- @_disallowFeatureSuppression ( NonescapableTypes)
330
- @_alwaysEmitIntoClient
331
- public func _elementsEqual( _ other: Self ) -> Bool {
332
- guard count == other. count else { return false }
333
- if count == 0 { return true }
334
-
335
- // This could be short-cut with a layout constraint
336
- // where stride equals size, as long as there is
337
- // at most 1 unused bit pattern, e.g.:
338
- // if Element is BitwiseEquatable {
339
- // return _swift_stdlib_memcmp(lhs.baseAddress, rhs.baseAddress, count) == 0
340
- // }
341
- if _pointer != other. _pointer {
342
- for o in 0 ..< count {
343
- if self [ unchecked: o] != other [ unchecked: o] { return false }
344
- }
345
- }
346
- return true
347
- }
348
-
349
- /// Returns a Boolean value indicating whether this span and a Collection
350
- /// contain equal elements in the same order.
351
- ///
352
- /// - Parameters:
353
- /// - other: A Collection to compare to this span.
354
- /// - Returns: `true` if this sequence and `other` contain equivalent items,
355
- /// using `areEquivalent` as the equivalence test; otherwise, `false.`
356
- ///
357
- /// - Complexity: O(*m*), where *m* is the lesser of the length of the
358
- /// sequence and the length of `other`.
359
- @_disallowFeatureSuppression ( NonescapableTypes)
360
- @_alwaysEmitIntoClient
361
- public func _elementsEqual( _ other: some Collection < Element > ) -> Bool {
362
- let equal = other. withContiguousStorageIfAvailable {
363
- _elementsEqual ( Span ( _unsafeElements: $0) )
364
- }
365
- if let equal { return equal }
366
-
367
- guard count == other. count else { return false }
368
- if count == 0 { return true }
369
-
370
- return _elementsEqual ( AnySequence ( other) )
371
- }
372
-
373
- /// Returns a Boolean value indicating whether this span and a Sequence
374
- /// contain equal elements in the same order.
375
- ///
376
- /// - Parameters:
377
- /// - other: A Sequence to compare to this span.
378
- /// - Returns: `true` if this sequence and `other` contain equivalent items,
379
- /// using `areEquivalent` as the equivalence test; otherwise, `false.`
380
- ///
381
- /// - Complexity: O(*m*), where *m* is the lesser of the length of the
382
- /// sequence and the length of `other`.
383
- @_disallowFeatureSuppression ( NonescapableTypes)
384
- @_alwaysEmitIntoClient
385
- public func _elementsEqual( _ other: some Sequence < Element > ) -> Bool {
386
- var offset = 0
387
- for otherElement in other {
388
- if offset >= count { return false }
389
- if self [ unchecked: offset] != otherElement { return false }
390
- offset += 1
391
- }
392
- return offset == count
393
- }
394
- }
395
-
396
- @_disallowFeatureSuppression ( NonescapableTypes)
397
318
@available ( SwiftStdlib 6 . 1 , * )
398
319
extension Span where Element: ~ Copyable {
399
320
@@ -674,7 +595,9 @@ extension Span where Element: BitwiseCopyable {
674
595
public func withUnsafeBytes< E: Error , Result: ~ Copyable> (
675
596
_ body: ( _ buffer: UnsafeRawBufferPointer ) throws ( E ) -> Result
676
597
) throws ( E ) -> Result {
677
- try RawSpan( _elements: self ) . withUnsafeBytes( body)
598
+ try body(
599
+ . init( start: _pointer , count: _count * MemoryLayout< Element > . stride )
600
+ )
678
601
}
679
602
}
680
603
0 commit comments