Skip to content

[stdlib] Force-inline some Sequence/Collection customization points #19683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ extension Collection {
///
/// - Complexity: Hopefully less than O(`count`).
@inlinable
@inline(__always)
public // dispatching
func _customIndexOfEquatableElement(_: Element) -> Index?? {
return nil
Expand All @@ -1283,6 +1284,7 @@ extension Collection {
///
/// - Complexity: Hopefully less than O(`count`).
@inlinable
@inline(__always)
public // dispatching
func _customLastIndexOfEquatableElement(_ element: Element) -> Index?? {
return nil
Expand Down Expand Up @@ -1802,6 +1804,7 @@ extension Collection where SubSequence == Self {

extension Collection {
@inlinable
@inline(__always)
public func _preprocessingPass<R>(
_ preprocess: () throws -> R
) rethrows -> R? {
Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/core/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -905,13 +905,15 @@ extension Sequence {
}

@inlinable
@inline(__always)
public func _preprocessingPass<R>(
_ preprocess: () throws -> R
) rethrows -> R? {
return nil
}

@inlinable
@inline(__always)
public func _customContainsEquatableElement(
_ element: Iterator.Element
) -> Bool? {
Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/core/Set.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ extension Set: Sequence {
}

@inlinable
@inline(__always)
public func _customContainsEquatableElement(_ member: Element) -> Bool? {
return contains(member)
}
Expand Down Expand Up @@ -361,13 +362,15 @@ extension Set: Collection {
}

@inlinable
@inline(__always)
public func _customIndexOfEquatableElement(
_ member: Element
) -> Index?? {
return Optional(firstIndex(of: member))
}

@inlinable
@inline(__always)
public func _customLastIndexOfEquatableElement(
_ member: Element
) -> Index?? {
Expand Down