mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: Add some inlining attributes to help the optimizer getting the right inlining decisions.
This is more or less a workaround for some optimizations (mainly ARC opt) to avoid performance degradation with the upcoming inliner changes In some situations it makes a big difference for ARC opt if a function is inlined or not, althought this shouldn't be the case.
This commit is contained in:
@@ -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()
|
||||
}
|
||||
@@ -1950,6 +1954,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))
|
||||
@@ -2077,6 +2082,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) {
|
||||
|
||||
@@ -2163,6 +2169,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.
|
||||
@@ -2198,6 +2205,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.
|
||||
@@ -2879,6 +2887,7 @@ internal struct _Cocoa${Self}Storage : _HashStorage {
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
@inline(__always)
|
||||
internal func maybeGet(key: Key) -> Value? {
|
||||
|
||||
%if Self == 'Set':
|
||||
@@ -3117,6 +3126,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) {
|
||||
@@ -3207,6 +3217,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)
|
||||
@@ -3527,6 +3538,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):
|
||||
@@ -3987,6 +3999,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()
|
||||
|
||||
Reference in New Issue
Block a user