Skip to content

Commit 25b8663

Browse files
committed
[SE-0101] .size to .stride
1 parent 595302e commit 25b8663

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Foundation/Data.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
194194
///
195195
/// - parameter buffer: A buffer pointer to copy. The size is calculated from `SourceType` and `buffer.count`.
196196
public init<SourceType>(buffer: UnsafeBufferPointer<SourceType>) {
197-
_wrapped = _SwiftNSData(immutableObject: NSData(bytes: buffer.baseAddress, length: MemoryLayout<SourceType>.size * buffer.count))
197+
_wrapped = _SwiftNSData(immutableObject: NSData(bytes: buffer.baseAddress, length: MemoryLayout<SourceType>.stride * buffer.count))
198198
}
199199

200200
/// Initialize a `Data` with the contents of an Array.
@@ -362,7 +362,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
362362

363363
/// Copy the contents of the data into a buffer.
364364
///
365-
/// 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.
365+
/// 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.
366366
/// - precondition: The range must be within the bounds of the data. Otherwise `fatalError` is called.
367367
/// - parameter buffer: A buffer to copy the data into.
368368
/// - 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.
@@ -380,9 +380,9 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
380380
precondition(r.upperBound >= 0)
381381
precondition(r.upperBound <= cnt, "The range is outside the bounds of the data")
382382

383-
copyRange = r.lowerBound..<(r.lowerBound + Swift.min(buffer.count * MemoryLayout<DestinationType>.size, r.count))
383+
copyRange = r.lowerBound..<(r.lowerBound + Swift.min(buffer.count * MemoryLayout<DestinationType>.stride, r.count))
384384
} else {
385-
copyRange = 0..<Swift.min(buffer.count * MemoryLayout<DestinationType>.size, cnt)
385+
copyRange = 0..<Swift.min(buffer.count * MemoryLayout<DestinationType>.stride, cnt)
386386
}
387387

388388
guard !copyRange.isEmpty else { return 0 }
@@ -470,7 +470,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
470470
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
471471
public mutating func append<SourceType>(_ buffer : UnsafeBufferPointer<SourceType>) {
472472
_applyUnmanagedMutation {
473-
$0.append(buffer.baseAddress!, length: buffer.count * MemoryLayout<SourceType>.size)
473+
$0.append(buffer.baseAddress!, length: buffer.count * MemoryLayout<SourceType>.stride)
474474
}
475475
}
476476

0 commit comments

Comments
 (0)