mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: protocol extensions: de-underscore indexOf()
Swift SVN r28244
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!])
|
||||
}
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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?")
|
||||
|
||||
@@ -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")!])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user