From 52af7cdda70be39b7b5866c709f615d6f27587fe Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Fri, 29 Jul 2016 15:11:27 +0900 Subject: [PATCH 1/2] [SE-0101] Migrate sizeof family to MemoryLayout --- src/swift/Data.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/swift/Data.swift b/src/swift/Data.swift index 8c1154d3e..765bd6b74 100644 --- a/src/swift/Data.swift +++ b/src/swift/Data.swift @@ -80,7 +80,7 @@ public struct DispatchData : RandomAccessCollection { var size = 0 let data = CDispatch.dispatch_data_create_map(__wrapped.__wrapped, &ptr, &size) let contentPtr = ptr!.bindMemory( - to: ContentType.self, capacity: size / strideof(ContentType.self)) + to: ContentType.self, capacity: size / MemoryLayout.stride) defer { _fixLifetime(data) } return try body(contentPtr) } @@ -118,7 +118,7 @@ public struct DispatchData : RandomAccessCollection { /// /// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`. public mutating func append(_ buffer : UnsafeBufferPointer) { - self.append(UnsafePointer(buffer.baseAddress!), count: buffer.count * sizeof(SourceType.self)) + self.append(UnsafePointer(buffer.baseAddress!), count: buffer.count * MemoryLayout.size) } private func _copyBytesHelper(to pointer: UnsafeMutablePointer, from range: CountableRange) { @@ -151,7 +151,7 @@ public struct DispatchData : RandomAccessCollection { /// Copy the contents of the data into a buffer. /// - /// 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. + /// This function copies the bytes in `range` from the data into the buffer. If the count of the `range` is greater than `MemoryLayout.size * buffer.count` then the first N bytes will be copied into the buffer. /// - precondition: The range must be within the bounds of the data. Otherwise `fatalError` is called. /// - parameter buffer: A buffer to copy the data into. /// - 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. @@ -169,9 +169,9 @@ public struct DispatchData : RandomAccessCollection { precondition(r.endIndex >= 0) precondition(r.endIndex <= cnt, "The range is outside the bounds of the data") - copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * sizeof(DestinationType.self), r.count)) + copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * MemoryLayout.size, r.count)) } else { - copyRange = 0...size, cnt) } guard !copyRange.isEmpty else { return 0 } From fae8166fa092df39f69453d7feb57802cc45c70e Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Fri, 29 Jul 2016 20:40:54 +0900 Subject: [PATCH 2/2] [SE-0101] .size to .stride --- src/swift/Data.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/swift/Data.swift b/src/swift/Data.swift index 765bd6b74..893228c58 100644 --- a/src/swift/Data.swift +++ b/src/swift/Data.swift @@ -118,7 +118,7 @@ public struct DispatchData : RandomAccessCollection { /// /// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`. public mutating func append(_ buffer : UnsafeBufferPointer) { - self.append(UnsafePointer(buffer.baseAddress!), count: buffer.count * MemoryLayout.size) + self.append(UnsafePointer(buffer.baseAddress!), count: buffer.count * MemoryLayout.stride) } private func _copyBytesHelper(to pointer: UnsafeMutablePointer, from range: CountableRange) { @@ -169,9 +169,9 @@ public struct DispatchData : RandomAccessCollection { precondition(r.endIndex >= 0) precondition(r.endIndex <= cnt, "The range is outside the bounds of the data") - copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * MemoryLayout.size, r.count)) + copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * MemoryLayout.stride, r.count)) } else { - copyRange = 0...size, cnt) + copyRange = 0...stride, cnt) } guard !copyRange.isEmpty else { return 0 }