[stdlib] Restore a combination of 11 commits

...but remove all new uses of closures, to make things easier on the
optimizer.

Swift SVN r23183
This commit is contained in:
Dave Abrahams
2014-11-08 20:04:29 +00:00
parent cb80bb3057
commit 2794fe3a13
11 changed files with 127 additions and 160 deletions

View File

@@ -70,29 +70,28 @@ class _IndirectArrayBuffer {
self.needsElementTypeCheck = false
}
var buffer: AnyObject?
var buffer: AnyObject
var isMutable: Bool
var isCocoa: Bool
var needsElementTypeCheck: Bool
func getNativeBufferOf<T>(_: T.Type) -> _ContiguousArrayBuffer<T> {
_sanityCheck(!isCocoa)
return _ContiguousArrayBuffer(
buffer != nil ? unsafeBitCast(buffer, _ContiguousArrayStorage<T>.self) : nil)
return _ContiguousArrayBuffer(unsafeDowncast(buffer))
}
func getCocoa() -> _NSArrayCoreType {
_sanityCheck(isCocoa)
return unsafeBitCast(buffer!, _NSArrayCoreType.self)
return Builtin.bridgeFromRawPointer(Builtin.bridgeToRawPointer(buffer))
}
}
public struct _ArrayBuffer<T> : _ArrayBufferType {
var storage: Builtin.NativeObject?
var storage: Builtin.NativeObject
var indirect: _IndirectArrayBuffer {
_sanityCheck(_isClassOrObjCExistential(T.self))
return Builtin.castFromNativeObject(storage!)
return Builtin.castFromNativeObject(storage)
}
public typealias Element = T
@@ -139,8 +138,7 @@ extension _ArrayBuffer {
public
init(_ source: NativeBuffer) {
if !_isClassOrObjCExistential(T.self) {
self.storage
= (source._storage != nil) ? Builtin.castToNativeObject(source._storage!) : nil
self.storage = Builtin.castToNativeObject(source._storage)
}
else {
self.storage = Builtin.castToNativeObject(
@@ -162,7 +160,7 @@ extension _ArrayBuffer {
_isBridgedToObjectiveC(T.self),
"Array element type is not bridged to ObjectiveC")
return _fastPath(_isNative) ? _native._asCocoaArray() : _nonNative!
return _fastPath(_isNative) ? _native._asCocoaArray() : _nonNative
}
var _hasMutableBuffer: Bool {
@@ -234,7 +232,7 @@ extension _ArrayBuffer {
}
}
else if !subRange.isEmpty {
let ns = _nonNative!
let ns = _nonNative
// Could be sped up, e.g. by using
// enumerateObjectsAtIndexes:options:usingBlock:
for i in subRange {
@@ -257,7 +255,7 @@ extension _ArrayBuffer {
return _native._uninitializedCopy(subRange, target: target)
}
let nonNative = _nonNative!
let nonNative = _nonNative
let nsSubRange = SwiftShims._SwiftNSRange(
location:subRange.startIndex,
@@ -292,7 +290,7 @@ extension _ArrayBuffer {
let subRangeCount = Swift.count(subRange)
// Look for contiguous storage in the NSArray
let cocoa = _CocoaArrayWrapper(nonNative!)
let cocoa = _CocoaArrayWrapper(nonNative)
let start = cocoa.contiguousStorage(subRange)
if start != nil {
return _SliceBuffer(owner: nonNative, start: UnsafeMutablePointer(start),
@@ -326,7 +324,7 @@ extension _ArrayBuffer {
public
var count: Int {
get {
return _fastPath(_isNative) ? _native.count : _nonNative!.count
return _fastPath(_isNative) ? _native.count : _nonNative.count
}
set {
_sanityCheck(_isNative, "attempting to update count of Cocoa array")
@@ -348,7 +346,7 @@ extension _ArrayBuffer {
/// How many elements the buffer can store without reallocation
public
var capacity: Int {
return _fastPath(_isNative) ? _native.capacity : _nonNative!.count
return _fastPath(_isNative) ? _native.capacity : _nonNative.count
}
/// Get/set the value of the ith element
@@ -361,7 +359,7 @@ extension _ArrayBuffer {
if _fastPath(_isNative) {
return _native[i]
}
return unsafeBitCast(_nonNative!.objectAtIndex(i), T.self)
return unsafeBitCast(_nonNative.objectAtIndex(i), T.self)
}
nonmutating set {
@@ -383,7 +381,7 @@ extension _ArrayBuffer {
body: (UnsafeBufferPointer<Element>)->R
) -> R {
if _isClassOrObjCExistential(T.self) {
if _nonNative != nil {
if !_isNative {
indirect.replaceStorage(_copyCollectionToNativeArrayBuffer(self))
}
}
@@ -411,8 +409,8 @@ extension _ArrayBuffer {
/// An object that keeps the elements stored in this buffer alive
public
var owner: AnyObject? {
return _fastPath(_isNative) ? _native._storage : _nonNative!
var owner: AnyObject {
return _fastPath(_isNative) ? _native._storage : _nonNative
}
/// A value that identifies the storage used by the buffer. Two
@@ -422,11 +420,8 @@ extension _ArrayBuffer {
if _isNative {
return _native.identity
}
else if let cocoa = _nonNative {
return unsafeAddressOf(cocoa)
}
else {
return nil
return unsafeAddressOf(_nonNative)
}
}
@@ -474,11 +469,10 @@ extension _ArrayBuffer {
/// Our native representation, if any. If there's no native
/// representation, the result is an empty buffer.
typealias _OptStorage = _ContiguousArrayStorage<T>?
var _native: NativeBuffer {
if !_isClassOrObjCExistential(T.self) {
return NativeBuffer(
unsafeBitCast(storage, _OptStorage.self))
let s: _ContiguousArrayStorageBase = Builtin.castFromNativeObject(storage)
return NativeBuffer(s)
}
else {
let i = indirect
@@ -488,14 +482,11 @@ extension _ArrayBuffer {
}
}
var _nonNative: _NSArrayCoreType? {
if !_isClassOrObjCExistential(T.self) {
return nil
}
else {
let i = indirect
return _fastPath(!i.isCocoa) ? nil : i.getCocoa()
}
var _nonNative: _NSArrayCoreType {
_sanityCheck(_isClassOrObjCExistential(T.self))
let i = indirect
_sanityCheck(i.isCocoa)
return i.getCocoa()
}
}