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