implement SE 184: add allocation methods to Unsafe buffer pointers, drop all parameters from deallocation, adjust namings, and add repeated-value assignment methods

This commit is contained in:
taylor swift
2017-11-06 14:40:15 -06:00
committed by Andrew Trick
parent c7d33e70d3
commit c85880899d
42 changed files with 561 additions and 263 deletions

View File

@@ -137,7 +137,7 @@ public final class _DataStorage {
}
return try apply(UnsafeRawBufferPointer(start: d.bytes.advanced(by: range.lowerBound - _offset), count: Swift.min(range.count, len)))
} else {
var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count)
var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout<UInt>.alignment)
defer { buffer.deallocate() }
let sliceRange = NSRange(location: range.lowerBound - _offset, length: range.count)
var enumerated = 0
@@ -168,7 +168,7 @@ public final class _DataStorage {
}
return try apply(UnsafeRawBufferPointer(start: d.bytes.advanced(by: range.lowerBound - _offset), count: Swift.min(range.count, len)))
} else {
var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count)
var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout<UInt>.alignment)
defer { buffer.deallocate() }
let sliceRange = NSRange(location: range.lowerBound - _offset, length: range.count)
var enumerated = 0

View File

@@ -224,9 +224,9 @@ extension NSDictionary {
// Allocate a buffer containing both the keys and values.
let buffer = UnsafeMutableRawPointer.allocate(
bytes: totalSize, alignedTo: alignment)
byteCount: totalSize, alignment: alignment)
defer {
buffer.deallocate(bytes: totalSize, alignedTo: alignment)
buffer.deallocate()
_fixLifetime(otherDictionary)
}

View File

@@ -177,9 +177,9 @@ extension NSSet {
assert(alignment == MemoryLayout<AnyObject>.alignment)
let rawBuffer = UnsafeMutableRawPointer.allocate(
bytes: bufferSize, alignedTo: alignment)
byteCount: bufferSize, alignment: alignment)
defer {
rawBuffer.deallocate(bytes: bufferSize, alignedTo: alignment)
rawBuffer.deallocate()
_fixLifetime(anSet)
}
let valueBuffer = rawBuffer.bindMemory(