stdlib: in Array bridging code, use the same pattern as Set and Dictionary use

Also, simplify the code by removing an unused parameter.  NFC.

Swift SVN r28607
This commit is contained in:
Dmitri Hrybenko
2015-05-15 03:44:37 +00:00
parent db7857c5af
commit d8d50e1815
3 changed files with 29 additions and 28 deletions

View File

@@ -1233,21 +1233,15 @@ extension Array {
return nil
}
/// Construct from the given `_NSArrayCoreType`.
/// Private initializer used for bridging.
///
/// If `noCopy` is `true`, either `source` must be known to be immutable,
/// or the resulting `Array` must not survive across code that could mutate
/// `source`.
public init(
_fromCocoaArray source: _NSArrayCoreType,
noCopy: Bool = false) {
let selectedSource: _NSArrayCoreType =
noCopy ?
source :
unsafeBitCast(
source.copyWithZone(nil),
_NSArrayCoreType.self)
self = Array(_ArrayBuffer(nsArray: selectedSource))
/// Only use this initializer when both conditions are true:
///
/// * it is statically known that the given `NSArray` is immutable;
/// * `T` is bridged verbatim to Objective-C (i.e.,
/// is a reference type).
public init(_immutableCocoaArray: _NSArrayCoreType) {
self = Array(_ArrayBuffer(nsArray: _immutableCocoaArray))
}
}
#endif