stdlib: add a hook for dynamic dispatch in CollectionType.find()

This hook allows Set.find() to be equally efficient in static and
generic contexts.

This time, with correct tests.

Swift SVN r27404
This commit is contained in:
Dmitri Hrybenko
2015-04-17 05:03:28 +00:00
parent e94b0f9b40
commit 02d254047b
5 changed files with 194 additions and 3 deletions

View File

@@ -49,9 +49,11 @@ extension CollectionType where Self.${GElement} : Equatable {
///
/// Complexity: O(\ `self.count()`\ )
final public func _prext_find(element: ${GElement}) -> Index? {
// FIXME: dynamic dispatch for Set and Dictionary.
// FIXME: _prext_indices
for i in indices(self) {
if let result? = _customFindEquatableElement(element) {
return result
}
for i in self._prext_indices {
if self[i] == element {
return i
}