stdlib: protocol extensions: de-underscore indexOf()

Swift SVN r28244
This commit is contained in:
Dmitri Hrybenko
2015-05-07 00:30:33 +00:00
parent 25e74d21db
commit f76ca6243e
9 changed files with 22 additions and 21 deletions

View File

@@ -25,7 +25,7 @@ public struct _FDInputStream {
public mutating func getline() -> String? {
if let newlineIndex =
find(_buffer[0..<_bufferUsed], UInt8(UnicodeScalar("\n").value)) {
_buffer[0..<_bufferUsed].indexOf(UInt8(UnicodeScalar("\n").value)) {
var result = String._fromWellFormedCodeUnitSequence(
UTF8.self, input: _buffer[0..<newlineIndex])
_buffer.removeRange(0...newlineIndex)

View File

@@ -34,11 +34,12 @@ public func maxElement<
/// `value` is not found.
///
/// - complexity: O(`count(domain)`)
@availability(*, unavailable, message="call the 'indexOf()' method on the collection")
public func find<
C: CollectionType where C.Generator.Element : Equatable
>(domain: C, _ value: C.Generator.Element) -> C.Index? {
// FIXME(prext): remove this function when protocol extensions land.
return domain._prext_indexOf(value)
return domain.indexOf(value)
}
/// Return the lesser of `x` and `y`

View File

@@ -72,7 +72,7 @@ extension _CollectionDefaultsType {
return distance(startIndex, endIndex)
}
/// Customization point for `SequenceType._prext_indexOf()`.
/// Customization point for `SequenceType.indexOf()`.
///
/// Define this method if the collection can find an element in less than
/// O(N) by exploiting collection-specific knowledge.
@@ -159,7 +159,7 @@ public protocol CollectionType
/// O(N) otherwise.
func _prext_count() -> Index.Distance
/// Customization point for `SequenceType._prext_indexOf()`.
/// Customization point for `SequenceType.indexOf()`.
///
/// Define this method if the collection can find an element in less than
/// O(N) by exploiting collection-specific knowledge.

View File

@@ -48,7 +48,7 @@ extension CollectionType where ${GElement} : Equatable {
/// `value` is not found.
///
/// - complexity: O(`self.count()`)
final public func _prext_indexOf(element: ${GElement}) -> Index? {
final public func indexOf(element: ${GElement}) -> Index? {
if let result = _customIndexOfEquatableElement(element) {
return result
}
@@ -67,7 +67,7 @@ extension CollectionType {
/// corresponding value, or `nil` if such value is not found.
///
/// - complexity: O(`self.count()`)
final public func _prext_indexOf(
final public func indexOf(
@noescape predicate: (${GElement}) -> Bool
) -> Index? {
for i in indices(self) {

View File

@@ -2600,13 +2600,13 @@ func callStaticFind(
collection: MinimalForwardCollection<MinimalEquatableValue>,
_ element: MinimalEquatableValue
) -> MinimalForwardCollection<MinimalEquatableValue>.Index? {
return collection._prext_indexOf(element)
return collection.indexOf(element)
}
func callGenericFind<
C : CollectionType where C.Generator.Element : Equatable
>(collection: C, _ element: C.Generator.Element) -> C.Index? {
return collection._prext_indexOf(element)
return collection.indexOf(element)
}
% for dispatch in [ 'Static', 'Generic' ]:
@@ -2677,7 +2677,7 @@ func callStaticFind(
sequence: CollectionWithCustomFindMethod,
_ element: MinimalEquatableValue
) -> CollectionWithCustomFindMethod.Index? {
return sequence._prext_indexOf(element)
return sequence.indexOf(element)
}
% for dispatch in [ 'Static', 'Generic' ]:
@@ -2703,14 +2703,14 @@ SequenceTypeAlgorithms.test("find/WhereElementIsEquatable/CustomImplementation/$
func callGenericFind_<
C : CollectionType where C.Generator.Element : Equatable
>(collection: C, _ element: C.Generator.Element) -> C.Index? {
return collection._prext_indexOf(element)
return collection.indexOf(element)
}
func callStaticFind_(
set: Set<MinimalHashableValue>,
_ element: MinimalHashableValue
) -> Set<MinimalHashableValue>.Index? {
return set._prext_indexOf(element)
return set.indexOf(element)
}
% for dispatch in [ 'Static', 'Generic' ]:
@@ -2758,7 +2758,7 @@ SequenceTypeAlgorithms.test("find/Predicate") {
test.sequence.map { MinimalEquatableValue($0) })
let closureLifetimeTracker = LifetimeTracked(0)
expectEqual(1, LifetimeTracked.instances)
let result = s._prext_indexOf {
let result = s.indexOf {
(candidate) in
_blackHole(closureLifetimeTracker)
return candidate.value == test.element

View File

@@ -128,7 +128,7 @@ tests.test("ForwardCollection") {
let a1 = ContiguousArray(fc0)
expectEqual(a0, a1)
for e in a0 {
let i = find(fc0, e)
let i = fc0.indexOf(e)
expectNotEmpty(i)
expectEqual(e, fc0[i!])
}
@@ -156,7 +156,7 @@ tests.test("BidirectionalCollection") {
let a1 = ContiguousArray(lazy(bc0).reverse())
expectEqual(a0, a1)
for e in a0 {
let i = find(bc0, e)
let i = bc0.indexOf(e)
expectNotEmpty(i)
expectEqual(e, bc0[i!])
}
@@ -191,7 +191,7 @@ tests.test("RandomAccessCollection") {
let a1 = ContiguousArray(lazy(rc0).reverse())
expectEqual(a0, a1)
for e in a0 {
let i = find(rc0, e)
let i = rc0.indexOf(e)
expectNotEmpty(i)
expectEqual(e, rc0[i!])
}

View File

@@ -99,7 +99,7 @@ mirrors.test("BidirectionalStructure") {
let description = y.description
expectEqual(
"[nil: \"a\", nil: \"b\", nil: \"c\", nil: \"",
description[description.startIndex..<find(description, "d")!])
description[description.startIndex..<description.indexOf("d")!])
}
mirrors.test("LabeledStructure") {

View File

@@ -44,7 +44,7 @@ func testEquatable<E: Equatable>(x: E) {}
func test_Equatable() {
// CHECK-NEXT: Found 2.5 at index 1
let array: [NSNumber] = [1, 2.5, 3.14159]
if let index = find(array, 2.5) {
if let index = array.indexOf(2.5) {
println("Found \(array[index]) at index \(index)")
} else {
println("Did not find 2.5?")

View File

@@ -3775,11 +3775,11 @@ DictionaryTestSuite.test("misc") {
expectOptionalEqual(4, d3["four"])
expectOptionalEqual(5, d3["five"])
expectEqual(3, d.values[find(d.keys, "three")!])
expectEqual(4, d.values[find(d.keys, "four")!])
expectEqual(3, d.values[d.keys.indexOf("three")!])
expectEqual(4, d.values[d.keys.indexOf("four")!])
expectEqual(3, d3.values[find(d.keys, "three")!])
expectEqual(4, d3.values[find(d.keys, "four")!])
expectEqual(3, d3.values[d.keys.indexOf("three")!])
expectEqual(4, d3.values[d.keys.indexOf("four")!])
}
}