Skip to content

Commit 4897fd8

Browse files
committed
[SE-0101] .size to .stride
1 parent 5464492 commit 4897fd8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/swift/Data.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ public struct DispatchData : RandomAccessCollection {
118118
///
119119
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
120120
public mutating func append<SourceType>(_ buffer : UnsafeBufferPointer<SourceType>) {
121-
let count = buffer.count * MemoryLayout<SourceType>.stride;
122-
buffer.baseAddress?.withMemoryRebound(to: UInt8.self, capacity: count) {
123-
self.append($0, count: count)
124-
}
121+
let count = buffer.count * MemoryLayout<SourceType>.stride;
122+
buffer.baseAddress?.withMemoryRebound(to: UInt8.self, capacity: count) {
123+
self.append($0, count: count)
124+
}
125125
}
126126

127127
private func _copyBytesHelper(to pointer: UnsafeMutablePointer<UInt8>, from range: CountableRange<Index>) {
@@ -154,7 +154,7 @@ public struct DispatchData : RandomAccessCollection {
154154

155155
/// Copy the contents of the data into a buffer.
156156
///
157-
/// This function copies the bytes in `range` from the data into the buffer. If the count of the `range` is greater than `MemoryLayout<DestinationType>.size * buffer.count` then the first N bytes will be copied into the buffer.
157+
/// This function copies the bytes in `range` from the data into the buffer. If the count of the `range` is greater than `MemoryLayout<DestinationType>.stride * buffer.count` then the first N bytes will be copied into the buffer.
158158
/// - precondition: The range must be within the bounds of the data. Otherwise `fatalError` is called.
159159
/// - parameter buffer: A buffer to copy the data into.
160160
/// - parameter range: A range in the data to copy into the buffer. If the range is empty, this function will return 0 without copying anything. If the range is nil, as much data as will fit into `buffer` is copied.
@@ -172,17 +172,17 @@ public struct DispatchData : RandomAccessCollection {
172172
precondition(r.endIndex >= 0)
173173
precondition(r.endIndex <= cnt, "The range is outside the bounds of the data")
174174

175-
copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * MemoryLayout<DestinationType>.size, r.count))
175+
copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * MemoryLayout<DestinationType>.stride, r.count))
176176
} else {
177-
copyRange = 0..<Swift.min(buffer.count * MemoryLayout<DestinationType>.size, cnt)
177+
copyRange = 0..<Swift.min(buffer.count * MemoryLayout<DestinationType>.stride, cnt)
178178
}
179179

180180
guard !copyRange.isEmpty else { return 0 }
181181

182182
let bufferCapacity = buffer.count * MemoryLayout<DestinationType>.stride
183-
buffer.baseAddress?.withMemoryRebound(to: UInt8.self, capacity: bufferCapacity) {
184-
_copyBytesHelper(to: $0, from: copyRange)
185-
}
183+
buffer.baseAddress?.withMemoryRebound(to: UInt8.self, capacity: bufferCapacity) {
184+
_copyBytesHelper(to: $0, from: copyRange)
185+
}
186186
return copyRange.count
187187
}
188188

0 commit comments

Comments
 (0)