Skip to content

Update for SE-0107, rename initialize(with:) to initialize(to:). #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Foundation/NSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
}
let objects = UnsafeMutablePointer<AnyObject?>(allocatingCapacity: Int(cnt))
for idx in 0..<cnt {
objects.advanced(by: Int(idx)).initialize(with: aDecoder.decodeObject())
objects.advanced(by: Int(idx)).initialize(to: aDecoder.decodeObject())
}
self.init(objects: UnsafePointer<AnyObject?>(objects), count: Int(cnt))
objects.deinitialize(count: Int(cnt))
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSCFString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ internal func _CFSwiftStringGetBytes(_ str: AnyObject, encoding: CFStringEncodin
for idx in 0..<range.length {
let characterIndex = encodingView.index(start, offsetBy: idx + range.location)
let character = encodingView[characterIndex]
buffer.advanced(by: idx).initialize(with: character)
buffer.advanced(by: idx).initialize(to: character)
}
}
usedBufLen?.pointee = range.length
Expand All @@ -149,8 +149,8 @@ internal func _CFSwiftStringGetBytes(_ str: AnyObject, encoding: CFStringEncodin
let character = encodingView[start.advanced(by: idx + range.location)]
let byte0 = UInt8(character & 0x00ff)
let byte1 = UInt8((character >> 8) & 0x00ff)
buffer.advanced(by: idx * 2).initialize(with: byte0)
buffer.advanced(by: (idx * 2) + 1).initialize(with: byte1)
buffer.advanced(by: idx * 2).initialize(to: byte0)
buffer.advanced(by: (idx * 2) + 1).initialize(to: byte1)
}
}
// Every character was 2 bytes
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ extension Dictionary : _ObjectTypeBridgeable {
self.forEach {
let key = _NSObjectRepresentableBridge($0.0)
let value = _NSObjectRepresentableBridge($0.1)
keyBuffer.advanced(by: idx).initialize(with: key)
valueBuffer.advanced(by: idx).initialize(with: value)
keyBuffer.advanced(by: idx).initialize(to: key)
valueBuffer.advanced(by: idx).initialize(to: value)
idx += 1
}

Expand Down Expand Up @@ -131,8 +131,8 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
let keys = UnsafeMutablePointer<NSObject>(allocatingCapacity: Int(cnt))
let objects = UnsafeMutablePointer<AnyObject>(allocatingCapacity: Int(cnt))
for idx in 0..<cnt {
keys.advanced(by: Int(idx)).initialize(with: aDecoder.decodeObject()! as! NSObject)
objects.advanced(by: Int(idx)).initialize(with: aDecoder.decodeObject()!)
keys.advanced(by: Int(idx)).initialize(to: aDecoder.decodeObject()! as! NSObject)
objects.advanced(by: Int(idx)).initialize(to: aDecoder.decodeObject()!)
}
self.init(objects: UnsafePointer<AnyObject>(objects), forKeys: UnsafePointer<NSObject>(keys), count: Int(cnt))
keys.deinitialize(count: Int(cnt))
Expand Down
10 changes: 5 additions & 5 deletions Foundation/NSFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ public class FileManager: NSObject {

let fsRep = FileManager.default().fileSystemRepresentation(withPath: path)
let ps = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>(allocatingCapacity: 2)
ps.initialize(with: UnsafeMutablePointer(fsRep))
ps.advanced(by: 1).initialize(with: nil)
ps.initialize(to: UnsafeMutablePointer(fsRep))
ps.advanced(by: 1).initialize(to: nil)
let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
ps.deinitialize(count: 2)
ps.deallocateCapacity(2)
Expand Down Expand Up @@ -703,7 +703,7 @@ public class FileManager: NSObject {
}
let buf = UnsafeMutablePointer<Int8>(allocatingCapacity: len)
for i in 0..<len {
buf.advanced(by: i).initialize(with: 0)
buf.advanced(by: i).initialize(to: 0)
}
if !path._nsObject.getFileSystemRepresentation(buf, maxLength: len) {
buf.deinitialize(count: len)
Expand Down Expand Up @@ -914,8 +914,8 @@ extension FileManager {
if FileManager.default().fileExists(atPath: path) {
let fsRep = FileManager.default().fileSystemRepresentation(withPath: path)
let ps = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>(allocatingCapacity: 2)
ps.initialize(with: UnsafeMutablePointer(fsRep))
ps.advanced(by: 1).initialize(with: nil)
ps.initialize(to: UnsafeMutablePointer(fsRep))
ps.advanced(by: 1).initialize(to: nil)
_stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
ps.deinitialize(count: 2)
ps.deallocateCapacity(2)
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSOrderedSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ extension NSOrderedSet {
public convenience init(array: [AnyObject]) {
let buffer = UnsafeMutablePointer<AnyObject?>(allocatingCapacity: array.count)
for (idx, element) in array.enumerated() {
buffer.advanced(by: idx).initialize(with: element)
buffer.advanced(by: idx).initialize(to: element)
}
self.init(objects: buffer, count: array.count)
buffer.deinitialize(count: array.count)
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension Set : _ObjectTypeBridgeable {
let buffer = UnsafeMutablePointer<AnyObject?>(allocatingCapacity: count)

for (idx, obj) in enumerated() {
buffer.advanced(by: idx).initialize(with: _NSObjectRepresentableBridge(obj))
buffer.advanced(by: idx).initialize(to: _NSObjectRepresentableBridge(obj))
}

let set = NSSet(objects: buffer, count: count)
Expand Down Expand Up @@ -124,7 +124,7 @@ public class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
}
let objects = UnsafeMutablePointer<AnyObject?>(allocatingCapacity: Int(cnt))
for idx in 0..<cnt {
objects.advanced(by: Int(idx)).initialize(with: aDecoder.decodeObject())
objects.advanced(by: Int(idx)).initialize(to: aDecoder.decodeObject())
}
self.init(objects: UnsafePointer<AnyObject?>(objects), count: Int(cnt))
objects.deinitialize(count: Int(cnt))
Expand Down Expand Up @@ -203,7 +203,7 @@ public class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
public convenience init(array: [AnyObject]) {
let buffer = UnsafeMutablePointer<AnyObject?>(allocatingCapacity: array.count)
for (idx, element) in array.enumerated() {
buffer.advanced(by: idx).initialize(with: element)
buffer.advanced(by: idx).initialize(to: element)
}
self.init(objects: buffer, count: array.count)
buffer.deinitialize(count: array.count)
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ internal func _bytesInEncoding(_ str: NSString, _ encoding: String.Encoding, _ f
fatalError("Internal inconsistency; previously claimed getBytes returned success but failed with similar invocation")
}

UnsafeMutablePointer<Int8>(buffer).advanced(by: cLength).initialize(with: 0)
UnsafeMutablePointer<Int8>(buffer).advanced(by: cLength).initialize(to: 0)

return UnsafePointer<Int8>(buffer) // leaked and should be autoreleased via a NSData backing but we cannot here
}
Expand Down Expand Up @@ -884,12 +884,12 @@ extension NSString {
used = min(self.length, maxBufferCount - 1)
buffer.moveAssign(from: unsafeBitCast(_storage._core.startASCII, to: UnsafeMutablePointer<Int8>.self)
, count: used)
buffer.advanced(by: used).initialize(with: 0)
buffer.advanced(by: used).initialize(to: 0)
return true
}
}
if getBytes(UnsafeMutablePointer<Void>(buffer), maxLength: maxBufferCount, usedLength: &used, encoding: encoding, options: [], range: NSMakeRange(0, self.length), remaining: nil) {
buffer.advanced(by: used).initialize(with: 0)
buffer.advanced(by: used).initialize(to: 0)
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public class NSURL: NSObject, NSSecureCoding, NSCopying {

let _fsrBuffer = UnsafeMutablePointer<Int8>(allocatingCapacity: bufSize)
for i in 0..<bufSize {
_fsrBuffer.advanced(by: i).initialize(with: 0)
_fsrBuffer.advanced(by: i).initialize(to: 0)
}

if getFileSystemRepresentation(_fsrBuffer, maxLength: bufSize) {
Expand Down