Skip to content

Commit b6451f2

Browse files
rintarodas
authored andcommitted
[SE-0101] Migrate sizeof family to MemoryLayout
Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
1 parent 6cf609d commit b6451f2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/swift/Data.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public struct DispatchData : RandomAccessCollection {
8080
var size = 0
8181
let data = CDispatch.dispatch_data_create_map(__wrapped.__wrapped, &ptr, &size)
8282
let contentPtr = ptr!.bindMemory(
83-
to: ContentType.self, capacity: size / strideof(ContentType.self))
83+
to: ContentType.self, capacity: size / MemoryLayout<ContentType>.stride)
8484
defer { _fixLifetime(data) }
8585
return try body(contentPtr)
8686
}
@@ -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 `sizeof(DestinationType) * 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>.size * 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,9 +172,9 @@ 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 * sizeof(DestinationType.self), r.count))
175+
copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * MemoryLayout<DestinationType>.size, r.count))
176176
} else {
177-
copyRange = 0..<Swift.min(buffer.count * sizeof(DestinationType.self), cnt)
177+
copyRange = 0..<Swift.min(buffer.count * MemoryLayout<DestinationType>.size, cnt)
178178
}
179179

180180
guard !copyRange.isEmpty else { return 0 }

0 commit comments

Comments
 (0)