Skip to content

Commit

Permalink
RangeReplaceableCollection.insert(_:atIndex:) => .insert(_:at:)
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 9a9ff30 commit 727f011
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions docs/proposals/OptimizerEffects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ state.
var storage: ArrayStorage

@set_subobject
func setElement(elt: T, atIndex: Int) {
storage.set(elt, atIndex)
func setElement(elt: T, at index: Int) {
storage.set(elt, index)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ func checkPartition_${'Predicate' if predicate else 'WhereElementIsComparable'}(

% if slice:
elements.insert(
OpaqueValue(0xfffe, identity: 0xfffe), atIndex: 0)
OpaqueValue(0xfffe, identity: 0xfffe), at: 0)
elements.append(OpaqueValue(0xffff, identity: 0xffff))
% end

Expand All @@ -704,7 +704,7 @@ func checkPartition_${'Predicate' if predicate else 'WhereElementIsComparable'}(

% if slice:
elements.insert(
MinimalComparableValue(0xfffe, identity: 0xfffe), atIndex: 0)
MinimalComparableValue(0xfffe, identity: 0xfffe), at: 0)
elements.append(MinimalComparableValue(0xffff, identity: 0xffff))
% end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ self.test("\(testNamePrefix).insert()/semantics") {
for test in tests {
var c = makeWrappedCollection(test.collection)
let newElement = wrapValue(test.newElement)
c.insert(newElement, atIndex: test.indexSelection.indexIn(c))
c.insert(newElement, at: test.indexSelection.indexIn(c))
expectEqualSequence(
test.expected,
c.map { extractValue($0).value },
Expand Down
4 changes: 2 additions & 2 deletions stdlib/private/StdlibUnittest/LoggingWrappers.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ public struct LoggingRangeReplaceableCollection<
}

public mutating func insert(
newElement: Base.Iterator.Element, atIndex i: Base.Index
newElement: Base.Iterator.Element, at i: Base.Index
) {
++Log.insert[selfType]
base.insert(newElement, atIndex: i)
base.insert(newElement, at: i)
}

public mutating func removeAt(index: Base.Index) -> Base.Iterator.Element {
Expand Down
24 changes: 12 additions & 12 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2639,8 +2639,8 @@ internal enum _CollectionOperation : Equatable {
case Append
case AppendContentsOf(count: Int)
case ReplaceSubrange(bounds: Range<Int>, replacementCount: Int)
case Insert(atIndex: Int)
case InsertContentsOf(atIndex: Int, count: Int)
case Insert(at: Int)
case InsertContentsOf(at: Int, count: Int)
case RemoveAt(index: Int)
case RemoveLast
case RemoveRange(bounds: Range<Int>)
Expand Down Expand Up @@ -2673,20 +2673,20 @@ internal enum _CollectionOperation : Equatable {
invalidIndices,
with: Repeat(repeating: nextStateId, count: invalidIndices.count))

case Insert(let atIndex):
result.insert(nextStateId, atIndex: atIndex)
case Insert(let index):
result.insert(nextStateId, at: index)

let invalidIndices = atIndex..<result.endIndex
let invalidIndices = index..<result.endIndex
result.replaceSubrange(
invalidIndices,
with: Repeat(repeating: nextStateId, count: invalidIndices.count))

case InsertContentsOf(let atIndex, let count):
case InsertContentsOf(let index, let count):
result.insertContentsOf(
Repeat(repeating: nextStateId, count: count),
at: atIndex)
at: index)

let invalidIndices = atIndex..<result.endIndex
let invalidIndices = index..<result.endIndex
result.replaceSubrange(
invalidIndices,
with: Repeat(repeating: nextStateId, count: invalidIndices.count))
Expand Down Expand Up @@ -3601,9 +3601,9 @@ public struct ${Self}<T> : RangeReplaceableCollection {
replacementCount: bounds.count + newCount - oldCount))
}

public mutating func insert(newElement: T, atIndex i: ${Index}) {
_willMutate(.Insert(atIndex: i._offset))
elements.insert(newElement, atIndex: i.position)
public mutating func insert(newElement: T, at i: ${Index}) {
_willMutate(.Insert(at: i._offset))
elements.insert(newElement, at: i.position)
}

public mutating func insertContentsOf<
Expand All @@ -3615,7 +3615,7 @@ public struct ${Self}<T> : RangeReplaceableCollection {

if newCount - oldCount != 0 {
_willMutate(.InsertContentsOf(
atIndex: i._offset,
at: i._offset,
count: newCount - oldCount))
}
}
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 @@ -61,7 +61,7 @@ protocol _ArrayType
/// - Complexity: O(`self.count`).
///
/// - Requires: `i <= count`.
mutating func insert(newElement: Iterator.Element, atIndex i: Int)
mutating func insert(newElement: Iterator.Element, at i: Int)

/// Remove and return the element at the given index.
///
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 @@ -722,7 +722,7 @@ extension ${Self} : _ArrayType {
/// - Requires: `i <= count`.
///
/// - Complexity: O(`self.count`).
public mutating func insert(newElement: Element, atIndex i: Int) {
public mutating func insert(newElement: Element, at i: Int) {
_checkIndex(i)
self.replaceSubrange(i..<i, with: CollectionOfOne(newElement))
}
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 @@ -112,7 +112,7 @@ public protocol RangeReplaceableCollection : Collection {
/// Invalidates all indices with respect to `self`.
///
/// - Complexity: O(`self.count`).
mutating func insert(newElement: Iterator.Element, atIndex i: Index)
mutating func insert(newElement: Iterator.Element, at i: Index)

/// Insert `newElements` at index `i`.
///
Expand Down Expand Up @@ -189,7 +189,7 @@ extension RangeReplaceableCollection {
}

public mutating func append(newElement: Iterator.Element) {
insert(newElement, atIndex: endIndex)
insert(newElement, at: endIndex)
}

public mutating func appendContentsOf<
Expand All @@ -201,7 +201,7 @@ extension RangeReplaceableCollection {
}

public mutating func insert(
newElement: Iterator.Element, atIndex i: Index
newElement: Iterator.Element, at i: Index
) {
replaceSubrange(i..<i, with: CollectionOfOne(newElement))
}
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 @@ -687,9 +687,9 @@ extension String {
/// Invalidates all indices with respect to `self`.
///
/// - Complexity: O(`self.count`).
public mutating func insert(newElement: Character, atIndex i: Index) {
public mutating func insert(newElement: Character, at i: Index) {
withMutableCharacters {
(inout v: CharacterView) in v.insert(newElement, atIndex: i)
(inout v: CharacterView) in v.insert(newElement, at: 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 @@ -112,14 +112,14 @@ ${ArrayTy}Traps.test("PopFromEmpty") {
}

% for index in -1, 2:
${ArrayTy}Traps.test("${'insert(_:atIndex:)/%s' % index}")
${ArrayTy}Traps.test("${'insert(_:at:)/%s' % index}")
.skip(.Custom(
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.code {
var a: ${ArrayTy}<Int> = [42]
expectCrashLater()
a.insert(3, atIndex: ${index})
a.insert(3, at: ${index})
}
% end

Expand Down
6 changes: 3 additions & 3 deletions test/1_stdlib/NewArray.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func testCocoa() {
// CHECK-NEXT: [foo, bar, baz]

a = nsArrayOfStrings()
a.insert("bag", atIndex:2)
a.insert("bag", at: 2)
printSequence(a)
// CHECK-NEXT: [foo, bar, bag, baz]

Expand Down Expand Up @@ -440,7 +440,7 @@ func testSingleElementModifiers${A}() {
print(a.removeLast().value) // CHECK-NEXT: 9
printSequence(a) // CHECK-NEXT: [0, 1, 2, 3, 4, 5, 6, 7, 8]

a.insert(42, atIndex: 4)
a.insert(42, at: 4)
printSequence(a) // CHECK-NEXT: [0, 1, 2, 3, 42, 4, 5, 6, 7, 8]

print(a.removeAt(2).value) // CHECK-NEXT: 2
Expand Down Expand Up @@ -470,7 +470,7 @@ func testIsEmptyFirstLast${A}() {
print(a.removeLast().value) // CHECK-NEXT: 9
printSequence(a) // CHECK-NEXT: [0, 1, 2, 3, 4, 5, 6, 7, 8]
a.insert(42, atIndex: 4)
a.insert(42, at: 4)
printSequence(a) // CHECK-NEXT: [0, 1, 2, 3, 42, 4, 5, 6, 7, 8]
print(a.removeAt(2).value) // CHECK-NEXT: 2
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/RangeReplaceable.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RangeReplaceableTestSuite.test("appendContentsOf/dispatch") {

RangeReplaceableTestSuite.test("insert/dispatch") {
var tester = RangeReplaceableCollectionLog.dispatchTester([ OpaqueValue(1) ])
tester.insert(OpaqueValue(2), atIndex: tester.base.startIndex)
tester.insert(OpaqueValue(2), at: tester.base.startIndex)
expectCustomizable(tester, tester.log.insert)
}

Expand Down
4 changes: 2 additions & 2 deletions test/IDE/complete_from_stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func testArchetypeReplacement1<FOO : Equatable>(a: [FOO]) {

// PRIVATE_NOMINAL_MEMBERS_5: Begin completions
// PRIVATE_NOMINAL_MEMBERS_5-DAG: Decl[InstanceMethod]/CurrNominal: append({#(newElement): Equatable#})[#Void#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_5-DAG: Decl[InstanceMethod]/CurrNominal: insert({#(newElement): Equatable#}, {#atIndex: Int#})[#Void#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_5-DAG: Decl[InstanceMethod]/CurrNominal: insert({#(newElement): Equatable#}, {#at: Int#})[#Void#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_5-DAG: Decl[InstanceMethod]/CurrNominal: popLast()[#Equatable?#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_5-DAG: Decl[InstanceMethod]/Super: iterator()[#CollectionDefaultIterator<[Equatable]>#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_5-DAG: Decl[InstanceVar]/Super: isEmpty[#Bool#]{{; name=.+}}
Expand All @@ -138,7 +138,7 @@ func testArchetypeReplacement2<BAR : Equatable>(a: [BAR]) {

// PRIVATE_NOMINAL_MEMBERS_6: Begin completions
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/CurrNominal: append({#(newElement): Equatable#})[#Void#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/CurrNominal: insert({#(newElement): Equatable#}, {#atIndex: Int#})[#Void#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/CurrNominal: insert({#(newElement): Equatable#}, {#at: Int#})[#Void#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/CurrNominal: popLast()[#Equatable?#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/Super: dropFirst()[#ArraySlice<Equatable>#]{{; name=.+}}
// PRIVATE_NOMINAL_MEMBERS_6-DAG: Decl[InstanceMethod]/Super: dropLast()[#ArraySlice<Equatable>#]{{; name=.+}}
Expand Down
2 changes: 1 addition & 1 deletion test/Prototypes/CollectionTransformers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ final class _ForkJoinWorkDeque<T> {

func append(element: T) {
_dequeMutex.withLock {
_deque.insert(element, atIndex: 0)
_deque.insert(element, at: 0)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ ${Self}TestSuite.test("replaceSubrange()/IndexInvalidation") {
${Self}TestSuite.test("insert()/IndexInvalidation") {
var (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ])
let i1 = c1.startIndex.advancedBy(1)
c1.insert(OpaqueValue(4040), atIndex: i1)
c1.insert(OpaqueValue(4040), at: i1)
let i2 = c1.startIndex.advancedBy(1)

expectCrashLater()
Expand Down

0 comments on commit 727f011

Please sign in to comment.