Re-instate "stdlib: Add some inlining attributes to help the optimizer getting the right inlining decisions."

This re-instates commit 8b0e36779e
This commit is contained in:
Erik Eckstein
2016-03-29 15:47:53 -07:00
parent a95979bdd2
commit c0964a492d
5 changed files with 51 additions and 19 deletions

View File

@@ -419,6 +419,7 @@ public struct Set<Element : Hashable> :
/// Returns an iterator over the members.
///
/// - Complexity: O(1).
@inline(__always)
public func makeIterator() -> SetIterator<Element> {
return _variantStorage.makeIterator()
}
@@ -1038,6 +1039,7 @@ public struct Dictionary<Key : Hashable, Value> :
/// Returns the `Index` for the given key, or `nil` if the key is not
/// present in the dictionary.
@warn_unused_result
@inline(__always)
public func index(forKey key: Key) -> Index? {
// Complexity: amortized O(1) for native storage, O(N) when wrapping an
// NSDictionary.
@@ -1057,6 +1059,7 @@ public struct Dictionary<Key : Hashable, Value> :
/// Writing `nil` as the value for a given key erases that key from
/// `self`.
public subscript(key: Key) -> Value? {
@inline(__always)
get {
return _variantStorage.maybeGet(key)
}
@@ -1132,6 +1135,7 @@ public struct Dictionary<Key : Hashable, Value> :
/// Returns an iterator over the `(Key, Value)` pairs.
///
/// - Complexity: O(1).
@inline(__always)
public func makeIterator() -> DictionaryIterator<Key, Value> {
return _variantStorage.makeIterator()
}
@@ -1951,6 +1955,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
}
@warn_unused_result
@inline(__always)
internal func key(at i: Int) -> Key {
_precondition(i >= 0 && i < capacity)
_sanityCheck(isInitializedEntry(at: i))
@@ -2078,6 +2083,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
/// If the key is not present, returns the position where it could be
/// inserted.
@warn_unused_result
@inline(__always)
internal func _find(key: Key, startBucket: Int)
-> (pos: Index, found: Bool) {
@@ -2164,6 +2170,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
}
@warn_unused_result
@inline(__always)
internal func index(forKey key: Key) -> Index? {
if count == 0 {
// Fast path that avoids computing the hash of the key.
@@ -2199,6 +2206,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
}
@warn_unused_result
@inline(__always)
internal func maybeGet(key: Key) -> Value? {
if count == 0 {
// Fast path that avoids computing the hash of the key.
@@ -2880,6 +2888,7 @@ internal struct _Cocoa${Self}Storage : _HashStorage {
}
@warn_unused_result
@inline(__always)
internal func maybeGet(key: Key) -> Value? {
%if Self == 'Set':
@@ -3118,6 +3127,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
}
@warn_unused_result
@inline(__always)
internal func index(forKey key: Key) -> Index? {
if _fastPath(guaranteedNative) {
if let nativeIndex = asNative.index(forKey: key) {
@@ -3208,6 +3218,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
#endif
@warn_unused_result
@inline(__always)
internal func maybeGet(key: Key) -> Value? {
if _fastPath(guaranteedNative) {
return asNative.maybeGet(key)
@@ -3528,6 +3539,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
/// Returns an iterator over the `(Key, Value)` pairs.
///
/// - Complexity: O(1).
@inline(__always)
internal func makeIterator() -> ${Self}Iterator<${TypeParameters}> {
switch self {
case .native(let owner):
@@ -3988,6 +4000,7 @@ public struct ${Self}Iterator<${TypeParametersDecl}> : IteratorProtocol {
/// element exists.
///
/// - Precondition: No preceding call to `self.next()` has returned `nil`.
@inline(__always)
public mutating func next() -> ${Sequence}? {
if _fastPath(_guaranteedNative) {
return _nativeNext()

View File

@@ -412,31 +412,43 @@ public struct ManagedBufferPointer<Value, Element> : Equatable {
/// Offset from the allocated storage for `self` to the stored `Value`
internal static var _valueOffset: Int {
@inline(__always)
get {
return _roundUp(
sizeof(_HeapObject.self),
toAlignment: alignof(Value.self))
}
}
/// An **unmanaged** pointer to the storage for the `Value`
/// instance. Not safe to use without _fixLifetime calls to
/// guarantee it doesn't dangle
internal var _valuePointer: UnsafeMutablePointer<Value> {
@inline(__always)
get {
return UnsafeMutablePointer(_address + _My._valueOffset)
}
}
/// An **unmanaged** pointer to the storage for `Element`s. Not
/// safe to use without _fixLifetime calls to guarantee it doesn't
/// dangle.
internal var _elementPointer: UnsafeMutablePointer<Element> {
@inline(__always)
get {
return UnsafeMutablePointer(_address + _My._elementOffset)
}
}
/// Offset from the allocated storage for `self` to the `Element` storage
internal static var _elementOffset: Int {
@inline(__always)
get {
return _roundUp(
_valueOffset + sizeof(Value.self),
toAlignment: alignof(Element.self))
}
}
internal var _nativeBuffer: Builtin.NativeObject
}

View File

@@ -201,6 +201,7 @@ public struct _StringBuffer {
/// - parameter bounds: Range of the substring that the caller tries
/// to extend.
/// - parameter newUsedCount: The desired size of the substring.
@inline(__always)
mutating func grow(
oldBounds bounds: Range<UnsafePointer<_RawByte>>, newUsedCount: Int
) -> Bool {

View File

@@ -307,6 +307,8 @@ public struct _StringCore {
/// Get the Nth UTF-16 Code Unit stored.
public subscript(position: Int) -> UTF16.CodeUnit {
@inline(__always)
get {
_precondition(
position >= 0,
"subscript: index precedes String start")
@@ -324,6 +326,7 @@ public struct _StringCore {
_sanityCheckFailure("subscript: non-native string without objc runtime")
#endif
}
}
/// Write the string, in the given encoding, to output.
func encode<
@@ -519,6 +522,7 @@ public struct _StringCore {
_invariantCheck()
}
@inline(never)
mutating func append(rhs: _StringCore) {
_invariantCheck()
let minElementWidth

View File

@@ -41,6 +41,7 @@ extension String {
self.idx = pos
self.core = core
}
@inline(__always)
mutating func next() -> UTF16.CodeUnit? {
if idx == core.endIndex {
return nil
@@ -61,6 +62,7 @@ extension String {
///
/// - Precondition: The next value is representable.
@warn_unused_result
@inline(__always)
public func successor() -> Index {
var scratch = _ScratchIterator(_core, _position)
var decoder = UTF16()