Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do not pull] [stdlib] SE-0132 renamings #3793

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions benchmark/single-source/DropFirst.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public func run_DropFirstCountableRange(_ N: Int) {
let s = 0..<sequenceCount
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -99,7 +99,7 @@ public func run_DropFirstSequence(_ N: Int) {
let s = sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -110,7 +110,7 @@ public func run_DropFirstAnySequence(_ N: Int) {
let s = AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -121,7 +121,7 @@ public func run_DropFirstAnySeqCntRange(_ N: Int) {
let s = AnySequence(0..<sequenceCount)
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -132,7 +132,7 @@ public func run_DropFirstAnySeqCRangeIter(_ N: Int) {
let s = AnySequence((0..<sequenceCount).makeIterator())
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -143,7 +143,7 @@ public func run_DropFirstAnyCollection(_ N: Int) {
let s = AnyCollection(0..<sequenceCount)
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -154,7 +154,7 @@ public func run_DropFirstArray(_ N: Int) {
let s = Array(0..<sequenceCount)
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -165,7 +165,7 @@ public func run_DropFirstCountableRangeLazy(_ N: Int) {
let s = (0..<sequenceCount).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -176,7 +176,7 @@ public func run_DropFirstSequenceLazy(_ N: Int) {
let s = (sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -187,7 +187,7 @@ public func run_DropFirstAnySequenceLazy(_ N: Int) {
let s = (AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -198,7 +198,7 @@ public func run_DropFirstAnySeqCntRangeLazy(_ N: Int) {
let s = (AnySequence(0..<sequenceCount)).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -209,7 +209,7 @@ public func run_DropFirstAnySeqCRangeIterLazy(_ N: Int) {
let s = (AnySequence((0..<sequenceCount).makeIterator())).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -220,7 +220,7 @@ public func run_DropFirstAnyCollectionLazy(_ N: Int) {
let s = (AnyCollection(0..<sequenceCount)).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -231,7 +231,7 @@ public func run_DropFirstArrayLazy(_ N: Int) {
let s = (Array(0..<sequenceCount)).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/DropFirst.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public func run_DropFirst${Name}(_ N: Int) {
let s = ${Expr}
for _ in 1...20*N {
var result = 0
for element in s.dropFirst(dropCount) {
for element in s.removingPrefix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand Down
28 changes: 14 additions & 14 deletions benchmark/single-source/DropLast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public func run_DropLastCountableRange(_ N: Int) {
let s = 0..<sequenceCount
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -98,7 +98,7 @@ public func run_DropLastSequence(_ N: Int) {
let s = sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -109,7 +109,7 @@ public func run_DropLastAnySequence(_ N: Int) {
let s = AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -120,7 +120,7 @@ public func run_DropLastAnySeqCntRange(_ N: Int) {
let s = AnySequence(0..<sequenceCount)
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -131,7 +131,7 @@ public func run_DropLastAnySeqCRangeIter(_ N: Int) {
let s = AnySequence((0..<sequenceCount).makeIterator())
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -142,7 +142,7 @@ public func run_DropLastAnyCollection(_ N: Int) {
let s = AnyCollection(0..<sequenceCount)
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -153,7 +153,7 @@ public func run_DropLastArray(_ N: Int) {
let s = Array(0..<sequenceCount)
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -164,7 +164,7 @@ public func run_DropLastCountableRangeLazy(_ N: Int) {
let s = (0..<sequenceCount).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -175,7 +175,7 @@ public func run_DropLastSequenceLazy(_ N: Int) {
let s = (sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -186,7 +186,7 @@ public func run_DropLastAnySequenceLazy(_ N: Int) {
let s = (AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -197,7 +197,7 @@ public func run_DropLastAnySeqCntRangeLazy(_ N: Int) {
let s = (AnySequence(0..<sequenceCount)).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -208,7 +208,7 @@ public func run_DropLastAnySeqCRangeIterLazy(_ N: Int) {
let s = (AnySequence((0..<sequenceCount).makeIterator())).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -219,7 +219,7 @@ public func run_DropLastAnyCollectionLazy(_ N: Int) {
let s = (AnyCollection(0..<sequenceCount)).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand All @@ -230,7 +230,7 @@ public func run_DropLastArrayLazy(_ N: Int) {
let s = (Array(0..<sequenceCount)).lazy
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/DropLast.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public func run_DropLast${Name}(_ N: Int) {
let s = ${Expr}
for _ in 1...20*N {
var result = 0
for element in s.dropLast(dropCount) {
for element in s.removingSuffix(dropCount) {
result += element
}
CheckResults(result == sumCount)
Expand Down
8 changes: 4 additions & 4 deletions benchmark/single-source/StringEdits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ func edits(_ word: String) -> Set<String> {

for (left, right) in splits {
// drop a character
result.append(left + right.dropFirst())
result.append(left + right.removingFirst())

// transpose two characters
if let fst = right.first {
let drop1 = right.dropFirst()
let drop1 = right.removingFirst()
if let snd = drop1.first {
result.append(left + [snd,fst] + drop1.dropFirst())
result.append(left + [snd,fst] + drop1.removingFirst())
}
}

// replace each character with another
for letter in alphabet {
result.append(left + [letter] + right.dropFirst())
result.append(left + [letter] + right.removingFirst())
}

// insert rogue characters
Expand Down
12 changes: 6 additions & 6 deletions benchmark/single-source/StringMatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public let StringMatch = BenchmarkInfo(

extension String {
@inline(__always)
func dropFirst(_ n: Int = 1) -> String {
func removingPrefix(_ n: Int = 1) -> String {
let startIndex = self.index(self.startIndex, offsetBy: n)
return self[startIndex ..< self.endIndex]
}
Expand All @@ -33,7 +33,7 @@ extension String {
/* match: search for regexp anywhere in text */
func match(regexp: String, text: String) -> Bool {
if regexp.first == "^" {
return matchHere(regexp.dropFirst(), text)
return matchHere(regexp.removingFirst(), text)
}

var idx = text.startIndex
Expand All @@ -55,16 +55,16 @@ func matchHere(_ regexp: String, _ text: String) -> Bool {
return true
}

if let c = regexp.first, regexp.dropFirst().first == "*" {
return matchStar(c, regexp.dropFirst(2), text)
if let c = regexp.first, regexp.removingFirst().first == "*" {
return matchStar(c, regexp.removingPrefix(2), text)
}

if regexp.first == "$" && regexp.dropFirst().isEmpty {
if regexp.first == "$" && regexp.removingFirst().isEmpty {
return text.isEmpty
}

if let tc = text.first, let rc = regexp.first, rc == "." || tc == rc {
return matchHere(regexp.dropFirst(), text.dropFirst())
return matchHere(regexp.removingFirst(), text.removingFirst())
}

return false
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/Substring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private func equivalentWithDistinctBuffers() -> (String, Substring) {
s0 += "!"

// These two should be equal but with distinct buffers, both refcounted.
let a = Substring(s0).dropFirst()
let a = Substring(s0).removingFirst()
let b = String(a)
return (b, a)
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/utils/ArgParse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public func parseArgs(_ validOptions: [String]? = nil)
for arg in CommandLine.arguments[1..<CommandLine.arguments.count] {
// If the argument doesn't match the optional argument pattern. Add
// it to the positional argument list and continue...
if passThroughArgs || !arg.starts(with: "-") {
if passThroughArgs || !arg.hasPrefix("-") {
positionalArgs.append(arg)
continue
}
Expand Down
4 changes: 2 additions & 2 deletions docs/StdlibRationales.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ The `remove*()` method family on collections
--------------------------------------------

Protocol extensions for ``RangeReplaceableCollectionType`` define
``removeFirst(n: Int)`` and ``removeLast(n: Int)``. These functions remove
``removePrefix(n: Int)`` and ``removeSuffix(n: Int)``. These functions remove
exactly ``n`` elements; they don't clamp ``n`` to ``count`` or they could be
masking bugs.

Expand All @@ -146,7 +146,7 @@ overloads have a precondition that the collection is not empty. Another
possible design would be that they don't have preconditions and return
``Element?``. Doing so would make the overload set inconsistent: semantics of
different overloads would be significantly different. It would be surprising
that ``myData.removeFirst()`` and ``myData.removeFirst(1)`` are not equivalent.
that ``myData.removeFirst()`` and ``myData.removePrefix(1)`` are not equivalent.

Lazy functions that operate on sequences and collections
--------------------------------------------------------
Expand Down
Loading