stdlib: add an extension point for SequenceType.contains()

This makes the protocol extension as fast as static dispatch for
Set.contains().

Swift SVN r27396
This commit is contained in:
Dmitri Hrybenko
2015-04-17 02:09:59 +00:00
parent 0d6374bb58
commit 2bccb13463
4 changed files with 109 additions and 1 deletions

View File

@@ -261,7 +261,10 @@ extension SequenceType ${"" if preds else "where Self.Generator.Element : Compar
extension SequenceType where Self.Generator.Element : Equatable {
/// Return `true` iff `x` is in `self`.
final public func _prext_contains(element: ${GElement}) -> Bool {
// FIXME: dynamic dispatch for Set and Dictionary.
if let result? = _customContainsEquatableElement(element) {
return result
}
for e in self {
if e == element {
return true