@@ -407,7 +407,7 @@ internal final class __DataStorage : @unchecked Sendable {
407407 }
408408 _length = newLength
409409 __DataStorage. move ( _bytes!. advanced ( by: origLength) , bytes, length)
410- }
410+ } ==
411411
412412 @inlinable // This is @inlinable despite escaping the __DataStorage boundary layer because it is trivially computed.
413413 func get( _ index: Int ) -> UInt8 {
@@ -2709,35 +2709,36 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
27092709 /// Returns `true` if the two `Data` arguments are equal.
27102710 @inlinable // This is @inlinable as emission into clients is safe -- the concept of equality on Data will not change.
27112711 public static func == ( d1 : Data , d2 : Data ) -> Bool {
2712- let length1 = d1. count
2713- let length2 = d2. count
2714-
2715- // Unequal length data can never be equal
2716- guard length1 == length2 else {
2717- return false
2718- }
2719-
27202712 // See if both are empty
27212713 switch ( d1. _representation, d2. _representation) {
27222714 case ( . empty, . empty) :
27232715 return true
27242716 default :
2717+ // Continue on to checks below
27252718 break
27262719 }
27272720
2721+ let length1 = d1. count
2722+ let length2 = d2. count
2723+
2724+ // Unequal length data can never be equal
2725+ guard length1 == length2 else {
2726+ return false
2727+ }
2728+
27282729 if length1 > 0 {
27292730 return d1. withUnsafeBytes { ( b1: UnsafeRawBufferPointer ) in
27302731 return d2. withUnsafeBytes { ( b2: UnsafeRawBufferPointer ) in
27312732 // If they have the same base address and same count, it is equal
27322733 let b1Address = b1. baseAddress!
27332734 let b2Address = b2. baseAddress!
27342735
2735- if b1Address == b2Address {
2736+ guard b1Address != b2Address else {
27362737 return true
2737- } else {
2738- // Compare the contents
2739- return memcmp ( b1. baseAddress!, b2. baseAddress!, b2. count) == 0
27402738 }
2739+
2740+ // Compare the contents
2741+ return memcmp ( b1. baseAddress!, b2. baseAddress!, b2. count) == 0
27412742 }
27422743 }
27432744 }
0 commit comments