From 2f0f43a8692aab8a24a0d6386ba751024ca4c3be Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 2 Oct 2018 20:26:03 +0100 Subject: [PATCH 1/2] [stdlib] Dictionary, Set: Force-inline hidden Sequence/Collection customization points This should eliminate a branch, which should probably lead to a tiny overall code size improvement, as well as a tiny performance boost. --- stdlib/public/core/Dictionary.swift | 3 +++ stdlib/public/core/Set.swift | 3 +++ 2 files changed, 6 insertions(+) diff --git a/stdlib/public/core/Dictionary.swift b/stdlib/public/core/Dictionary.swift index 8169357875226..52715dd841083 100644 --- a/stdlib/public/core/Dictionary.swift +++ b/stdlib/public/core/Dictionary.swift @@ -1383,16 +1383,19 @@ extension Dictionary { } @inlinable + @inline(__always) public func _customContainsEquatableElement(_ element: Element) -> Bool? { return _variant.contains(element) } @inlinable + @inline(__always) public func _customIndexOfEquatableElement(_ element: Element) -> Index?? { return Optional(_variant.index(forKey: element)) } @inlinable + @inline(__always) public func _customLastIndexOfEquatableElement(_ element: Element) -> Index?? { // The first and last elements are the same because each element is unique. return _customIndexOfEquatableElement(element) diff --git a/stdlib/public/core/Set.swift b/stdlib/public/core/Set.swift index 2dadaabf386a7..6541ba75d28f0 100644 --- a/stdlib/public/core/Set.swift +++ b/stdlib/public/core/Set.swift @@ -266,6 +266,7 @@ extension Set: Sequence { } @inlinable + @inline(__always) public func _customContainsEquatableElement(_ member: Element) -> Bool? { return contains(member) } @@ -361,6 +362,7 @@ extension Set: Collection { } @inlinable + @inline(__always) public func _customIndexOfEquatableElement( _ member: Element ) -> Index?? { @@ -368,6 +370,7 @@ extension Set: Collection { } @inlinable + @inline(__always) public func _customLastIndexOfEquatableElement( _ member: Element ) -> Index?? { From 4615e18366d58abc8aefe3ad4ec4be39fae7cd84 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 2 Oct 2018 20:27:42 +0100 Subject: [PATCH 2/2] [stdlib] Force-inline trivial default implementations for hidden Sequence/Collection customization points This is usually a code size pessimization, but in this case the bodies are trivial, so inlining them eliminates a call + a conditional branch. --- stdlib/public/core/Collection.swift | 3 +++ stdlib/public/core/Sequence.swift | 2 ++ 2 files changed, 5 insertions(+) diff --git a/stdlib/public/core/Collection.swift b/stdlib/public/core/Collection.swift index f9dac4df4c9cc..ef8c14669f679 100644 --- a/stdlib/public/core/Collection.swift +++ b/stdlib/public/core/Collection.swift @@ -1267,6 +1267,7 @@ extension Collection { /// /// - Complexity: Hopefully less than O(`count`). @inlinable + @inline(__always) public // dispatching func _customIndexOfEquatableElement(_: Element) -> Index?? { return nil @@ -1283,6 +1284,7 @@ extension Collection { /// /// - Complexity: Hopefully less than O(`count`). @inlinable + @inline(__always) public // dispatching func _customLastIndexOfEquatableElement(_ element: Element) -> Index?? { return nil @@ -1802,6 +1804,7 @@ extension Collection where SubSequence == Self { extension Collection { @inlinable + @inline(__always) public func _preprocessingPass( _ preprocess: () throws -> R ) rethrows -> R? { diff --git a/stdlib/public/core/Sequence.swift b/stdlib/public/core/Sequence.swift index 6cd5ff0253005..85d154b181d93 100644 --- a/stdlib/public/core/Sequence.swift +++ b/stdlib/public/core/Sequence.swift @@ -905,6 +905,7 @@ extension Sequence { } @inlinable + @inline(__always) public func _preprocessingPass( _ preprocess: () throws -> R ) rethrows -> R? { @@ -912,6 +913,7 @@ extension Sequence { } @inlinable + @inline(__always) public func _customContainsEquatableElement( _ element: Iterator.Element ) -> Bool? {