@@ -1085,35 +1085,26 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
1085
1085
// slightly faster paths for common sequences
1086
1086
1087
1087
public init < S: Sequence > ( _ elements: S ) where S. Iterator. Element == UInt8 {
1088
- let underestimatedCount = elements. underestimatedCount
1089
- self . init ( count: underestimatedCount)
1090
-
1091
- let ( endIterator, _) = UnsafeMutableBufferPointer ( start: _backing. _bytes? . assumingMemoryBound ( to: UInt8 . self) , count: underestimatedCount) . initialize ( from: elements)
1092
- var iter = endIterator
1093
- while let byte = iter. next ( ) { self . append ( byte) }
1094
- }
1095
-
1096
- public init ( _ bytes: Array < UInt8 > ) {
1097
- self . init ( bytes: bytes)
1098
- }
1099
-
1100
- public init ( _ bytes: ArraySlice < UInt8 > ) {
1101
- self . init ( bytes: bytes)
1102
- }
1103
-
1104
- public init ( _ buffer: UnsafeBufferPointer < UInt8 > ) {
1105
- self . init ( buffer: buffer)
1106
- }
1107
-
1108
- public init ( _ buffer: UnsafeMutableBufferPointer < UInt8 > ) {
1109
- self . init ( buffer: buffer)
1110
- }
1111
-
1112
- public init ( _ data: Data ) {
1113
- _sliceRange = 0 ..< data. count
1114
- _backing = data. _backing. mutableCopy ( data. _sliceRange)
1088
+ if elements is Array < UInt8 > {
1089
+ self . init ( bytes: _identityCast ( elements, to: Array< UInt8> . self ) )
1090
+ } else if elements is ArraySlice < UInt8 > {
1091
+ self . init ( bytes: _identityCast ( elements, to: ArraySlice< UInt8> . self ) )
1092
+ } else if elements is UnsafeBufferPointer < UInt8 > {
1093
+ self . init ( buffer: _identityCast ( elements, to: UnsafeBufferPointer< UInt8> . self ) )
1094
+ } else if let buffer = elements as? UnsafeMutableBufferPointer < UInt8 > {
1095
+ self . init ( buffer: buffer)
1096
+ } else if let data = elements as? Data {
1097
+ self . init ( backing: data. _backing. mutableCopy ( data. _sliceRange) , range: 0 ..< data. count)
1098
+ } else {
1099
+ let underestimatedCount = elements. underestimatedCount
1100
+ self . init ( count: underestimatedCount)
1101
+
1102
+ let ( endIterator, _) = UnsafeMutableBufferPointer ( start: _backing. _bytes? . assumingMemoryBound ( to: UInt8 . self) , count: underestimatedCount) . initialize ( from: elements)
1103
+ var iter = endIterator
1104
+ while let byte = iter. next ( ) { self . append ( byte) }
1105
+ }
1115
1106
}
1116
-
1107
+
1117
1108
@_versioned
1118
1109
internal init ( backing: _DataStorage , range: Range < Index > ) {
1119
1110
_backing = backing
0 commit comments