Skip to content

Commit

Permalink
removeAtIndex() => removeAt()
Browse files Browse the repository at this point in the history
  • Loading branch information
gribozavr authored and Max Moiseev committed Dec 10, 2015
1 parent 2bec8ad commit 4b1be0e
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func checkPartition_${'Predicate' if predicate else 'WhereElementIsComparable'}(
expectEqual(0xfffe, extract(c.first!).identity)
expectEqual(0xffff, extract(c.last!).identity)
identities.removeLast()
identities.removeAtIndex(0)
identities.removeAt(0)
% end
expectEqualsUnordered(0..<sequence.count, identities)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ internal struct InsertContentsOfTest {
}
}

internal struct RemoveAtIndexTest {
internal struct RemoveAtTest {
let collection: [OpaqueValue<Int>]
let indexSelection: IndexSelection
let expectedRemovedElement: Int
Expand All @@ -165,7 +165,7 @@ internal struct RemoveAtIndexTest {
self.indexSelection = indexSelection
self.expectedRemovedElement = expectedRemovedElement
self.expectedCollection = expectedCollection
self.loc = SourceLoc(file, line, comment: "removeAtIndex() test data")
self.loc = SourceLoc(file, line, comment: "removeAt() test data")
}
}

Expand Down Expand Up @@ -656,30 +656,30 @@ self.test("\(testNamePrefix).insertContentsOf()/semantics") {
}

//===----------------------------------------------------------------------===//
// removeAtIndex()
// removeAt()
//===----------------------------------------------------------------------===//

self.test("\(testNamePrefix).removeAtIndex()/semantics") {
let tests: [RemoveAtIndexTest] = [
RemoveAtIndexTest(
self.test("\(testNamePrefix).removeAt()/semantics") {
let tests: [RemoveAtTest] = [
RemoveAtTest(
collection: [1010],
indexSelection: .Start,
expectedRemovedElement: 1010,
expectedCollection: []),

RemoveAtIndexTest(
RemoveAtTest(
collection: [1010, 2020, 3030],
indexSelection: .Start,
expectedRemovedElement: 1010,
expectedCollection: [2020, 3030]),

RemoveAtIndexTest(
RemoveAtTest(
collection: [1010, 2020, 3030],
indexSelection: .Middle,
expectedRemovedElement: 2020,
expectedCollection: [1010, 3030]),

RemoveAtIndexTest(
RemoveAtTest(
collection: [1010, 2020, 3030],
indexSelection: .Last,
expectedRemovedElement: 3030,
Expand All @@ -688,7 +688,7 @@ self.test("\(testNamePrefix).removeAtIndex()/semantics") {

for test in tests {
var c = makeWrappedCollection(test.collection)
let removedElement = c.removeAtIndex(test.indexSelection.indexIn(c))
let removedElement = c.removeAt(test.indexSelection.indexIn(c))
expectEqualSequence(
test.expectedCollection,
c.map { extractValue($0).value },
Expand Down
8 changes: 4 additions & 4 deletions stdlib/private/StdlibUnittest/LoggingWrappers.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class RangeReplaceableCollectionLog {
public static var appendContentsOf = TypeIndexed(0)
public static var insert = TypeIndexed(0)
public static var removeAll = TypeIndexed(0)
public static var removeAtIndex = TypeIndexed(0)
public static var removeAt = TypeIndexed(0)
public static var _customRemoveLast = TypeIndexed(0)
public static var _customRemoveLastN = TypeIndexed(0)
public static var removeRange = TypeIndexed(0)
Expand Down Expand Up @@ -165,9 +165,9 @@ public struct LoggingRangeReplaceableCollection<
base.insert(newElement, atIndex: i)
}

public mutating func removeAtIndex(index: Base.Index) -> Base.Iterator.Element {
++Log.removeAtIndex[selfType]
return base.removeAtIndex(index)
public mutating func removeAt(index: Base.Index) -> Base.Iterator.Element {
++Log.removeAt[selfType]
return base.removeAt(index)
}

public mutating func _customRemoveLast() -> Base.Iterator.Element? {
Expand Down
14 changes: 7 additions & 7 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2641,7 +2641,7 @@ internal enum _CollectionOperation : Equatable {
case ReplaceRange(subRange: Range<Int>, replacementCount: Int)
case Insert(atIndex: Int)
case InsertContentsOf(atIndex: Int, count: Int)
case RemoveAtIndex(index: Int)
case RemoveAt(index: Int)
case RemoveLast
case RemoveRange(subRange: Range<Int>)
case RemoveAll(keepCapacity: Bool)
Expand Down Expand Up @@ -2691,8 +2691,8 @@ internal enum _CollectionOperation : Equatable {
invalidIndices,
with: Repeat(repeating: nextStateId, count: invalidIndices.count))

case RemoveAtIndex(let index):
result.removeAtIndex(index)
case RemoveAt(let index):
result.removeAt(index)

let invalidIndices = index..<result.endIndex
result.replaceRange(
Expand Down Expand Up @@ -2747,7 +2747,7 @@ internal func == (

return lhsAtIndex == rhsAtIndex && lhsCount == rhsCount

case (.RemoveAtIndex(let lhsIndex), .RemoveAtIndex(let rhsIndex)):
case (.RemoveAt(let lhsIndex), .RemoveAt(let rhsIndex)):
return lhsIndex == rhsIndex

case (.RemoveLast, .RemoveLast):
Expand Down Expand Up @@ -3620,9 +3620,9 @@ public struct ${Self}<T> : RangeReplaceableCollection {
}
}

public mutating func removeAtIndex(i: ${Index}) -> T {
_willMutate(.RemoveAtIndex(index: i._offset))
return elements.removeAtIndex(i.position)
public mutating func removeAt(i: ${Index}) -> T {
_willMutate(.RemoveAt(index: i._offset))
return elements.removeAt(i.position)
}

public mutating func removeLast() -> T {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ArrayType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protocol _ArrayType
/// - Complexity: Worst case O(N).
///
/// - Requires: `count > index`.
mutating func removeAtIndex(index: Int) -> Iterator.Element
mutating func removeAt(index: Int) -> Iterator.Element

//===--- implementation detail -----------------------------------------===//

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Arrays.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ extension ${Self} : _ArrayType {
/// Invalidates all indices with respect to `self`.
///
/// - Complexity: O(`self.count`).
public mutating func removeAtIndex(index: Int) -> Element {
public mutating func removeAt(index: Int) -> Element {
let result = self[index]
self.replaceRange(index..<(index + 1), with: EmptyCollection())
return result
Expand Down
24 changes: 12 additions & 12 deletions stdlib/public/core/HashedCollections.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ internal protocol _HashStorageType {
func maybeGet(key: Key) -> Value?

mutating func updateValue(value: Value, forKey: Key) -> Value?
mutating func removeAtIndex(index: Index) -> SequenceElement
mutating func removeAt(index: Index) -> SequenceElement
mutating func removeValueForKey(key: Key) -> Value?
mutating func removeAll(keepCapacity keepCapacity: Bool)
var count: Int { get }
Expand Down Expand Up @@ -373,8 +373,8 @@ public struct Set<Element : Hashable> :
}

/// Remove the member referenced by the given index.
public mutating func removeAtIndex(index: Index) -> Element {
return _variantStorage.removeAtIndex(index)
public mutating func removeAt(index: Index) -> Element {
return _variantStorage.removeAt(index)
}

/// Erase all the elements. If `keepCapacity` is `true`, `capacity`
Expand Down Expand Up @@ -1078,8 +1078,8 @@ public struct Dictionary<Key : Hashable, Value> :
/// Invalidates all indices with respect to `self`.
///
/// - Complexity: O(`self.count`).
public mutating func removeAtIndex(index: Index) -> Element {
return _variantStorage.removeAtIndex(index)
public mutating func removeAt(index: Index) -> Element {
return _variantStorage.removeAt(index)
}

/// Remove a given key and the associated value from the dictionary.
Expand Down Expand Up @@ -2191,7 +2191,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
"don't call mutating methods on _Native${Self}Storage")
}

internal mutating func removeAtIndex(index: Index) -> SequenceElement {
internal mutating func removeAt(index: Index) -> SequenceElement {
_sanityCheckFailure(
"don't call mutating methods on _Native${Self}Storage")
}
Expand Down Expand Up @@ -2857,7 +2857,7 @@ internal struct _Cocoa${Self}Storage : _HashStorageType {
_sanityCheckFailure("can not mutate NS${Self}")
}

internal mutating func removeAtIndex(index: Index) -> SequenceElement {
internal mutating func removeAt(index: Index) -> SequenceElement {
_sanityCheckFailure("can not mutate NS${Self}")
}

Expand Down Expand Up @@ -3308,7 +3308,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
return oldValue
}

internal mutating func nativeRemoveAtIndex(
internal mutating func nativeRemoveAt(
nativeIndex: NativeIndex
) -> SequenceElement {
var nativeStorage = native
Expand All @@ -3332,14 +3332,14 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
return result
}

internal mutating func removeAtIndex(index: Index) -> SequenceElement {
internal mutating func removeAt(index: Index) -> SequenceElement {
if _fastPath(guaranteedNative) {
return nativeRemoveAtIndex(index._nativeIndex)
return nativeRemoveAt(index._nativeIndex)
}

switch self {
case .Native:
return nativeRemoveAtIndex(index._nativeIndex)
return nativeRemoveAt(index._nativeIndex)
case .Cocoa(let cocoaStorage):
#if _runtime(_ObjC)
// We have to migrate the data first. But after we do so, the Cocoa
Expand Down Expand Up @@ -4106,7 +4106,7 @@ extension ${Self} {
/// - Complexity: Amortized O(1)
public mutating func popFirst() -> Element? {
guard !isEmpty else { return nil }
return removeAtIndex(startIndex)
return removeAt(startIndex)
}
}

Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/core/RangeReplaceableCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public protocol RangeReplaceableCollection : Collection {
/// Invalidates all indices with respect to `self`.
///
/// - Complexity: O(`self.count`).
mutating func removeAtIndex(i: Index) -> Iterator.Element
mutating func removeAt(i: Index) -> Iterator.Element

/// Customization point for `removeLast()`. Implement this function if you
/// want to replace the default implementation.
Expand Down Expand Up @@ -212,7 +212,7 @@ extension RangeReplaceableCollection {
replaceRange(i..<i, with: newElements)
}

public mutating func removeAtIndex(index: Index) -> Iterator.Element {
public mutating func removeAt(index: Index) -> Iterator.Element {
_precondition(!isEmpty, "can't remove from an empty collection")
let result: Iterator.Element = self[index]
replaceRange(index...index, with: EmptyCollection())
Expand Down Expand Up @@ -318,7 +318,7 @@ extension RangeReplaceableCollection where Index : BidirectionalIndexType {
if let result = _customRemoveLast() {
return result
}
return removeAtIndex(endIndex.predecessor())
return removeAt(endIndex.predecessor())
}

/// Remove the last `n` elements.
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,9 @@ extension String {
/// Invalidates all indices with respect to `self`.
///
/// - Complexity: O(`self.count`).
public mutating func removeAtIndex(i: Index) -> Character {
public mutating func removeAt(i: Index) -> Character {
return withMutableCharacters {
(inout v: CharacterView) in v.removeAtIndex(i)
(inout v: CharacterView) in v.removeAt(i)
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/ArrayTraps.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ ${ArrayTy}Traps.test("${'insert(_:atIndex:)/%s' % index}")
% end

% for index in -1, 1, 2:
${ArrayTy}Traps.test("${'removeAtIndex(_:)/%s' % index}")
${ArrayTy}Traps.test("${'removeAt(_:)/%s' % index}")
.skip(.Custom(
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.code {
var a: ${ArrayTy}<Int> = [42]
expectCrashLater()
a.removeAtIndex(${index})
a.removeAt(${index})
}
% end
% end
Expand Down
10 changes: 5 additions & 5 deletions test/1_stdlib/DictionaryTraps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ DictionaryTraps.test("RemoveInvalidIndex1")
var d = Dictionary<Int, Int>()
let index = d.startIndex
expectCrashLater()
d.removeAtIndex(index)
d.removeAt(index)
}

DictionaryTraps.test("RemoveInvalidIndex2")
Expand All @@ -117,7 +117,7 @@ DictionaryTraps.test("RemoveInvalidIndex2")
var d = Dictionary<Int, Int>()
let index = d.endIndex
expectCrashLater()
d.removeAtIndex(index)
d.removeAt(index)
}

DictionaryTraps.test("RemoveInvalidIndex3")
Expand All @@ -128,7 +128,7 @@ DictionaryTraps.test("RemoveInvalidIndex3")
var d = [ 10: 1010, 20: 1020, 30: 1030 ]
let index = d.endIndex
expectCrashLater()
d.removeAtIndex(index)
d.removeAt(index)
}

DictionaryTraps.test("RemoveInvalidIndex4")
Expand All @@ -138,10 +138,10 @@ DictionaryTraps.test("RemoveInvalidIndex4")
.code {
var d = [ 10: 1010 ]
let index = d.indexForKey(10)!
d.removeAtIndex(index)
d.removeAt(index)
expectEmpty(d[10])
expectCrashLater()
d.removeAtIndex(index)
d.removeAt(index)
}

class TestObjCKeyTy : NSObject {
Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/NewArray.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func testSingleElementModifiers${A}() {
a.insert(42, atIndex: 4)
printSequence(a) // CHECK-NEXT: [0, 1, 2, 3, 42, 4, 5, 6, 7, 8]

print(a.removeAtIndex(2).value) // CHECK-NEXT: 2
print(a.removeAt(2).value) // CHECK-NEXT: 2
printSequence(a) // CHECK-NEXT: [0, 1, 3, 42, 4, 5, 6, 7, 8]
}
testSingleElementModifiers${A}()
Expand Down Expand Up @@ -473,7 +473,7 @@ func testIsEmptyFirstLast${A}() {
a.insert(42, atIndex: 4)
printSequence(a) // CHECK-NEXT: [0, 1, 2, 3, 42, 4, 5, 6, 7, 8]
print(a.removeAtIndex(2).value) // CHECK-NEXT: 2
print(a.removeAt(2).value) // CHECK-NEXT: 2
printSequence(a) // CHECK-NEXT: [0, 1, 3, 42, 4, 5, 6, 7, 8]
}
testIsEmptyFirstLast${A}()
Expand Down
6 changes: 3 additions & 3 deletions test/1_stdlib/RangeReplaceable.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ RangeReplaceableTestSuite.test("insertContentsOf/dispatch") {
expectCustomizable(tester, tester.log.insertContentsOf)
}

RangeReplaceableTestSuite.test("removeAtIndex/dispatch") {
RangeReplaceableTestSuite.test("removeAt/dispatch") {
var tester = RangeReplaceableCollectionLog.dispatchTester([ OpaqueValue(1) ])
tester.removeAtIndex(tester.base.startIndex)
expectCustomizable(tester, tester.log.removeAtIndex)
tester.removeAt(tester.base.startIndex)
expectCustomizable(tester, tester.log.removeAt)
}

RangeReplaceableTestSuite.test("removeLast/whereIndexIsBidirectional/dispatch") {
Expand Down
Loading

0 comments on commit 4b1be0e

Please sign in to comment.