Skip to content

Commit 5832da1

Browse files
committed
Refactor operations to be on String (swiftlang#664)
Finish refactoring logic onto String
1 parent 5ec1927 commit 5832da1

File tree

6 files changed

+131
-139
lines changed

6 files changed

+131
-139
lines changed

Sources/RegexBenchmark/Utils/Stats.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import Foundation
33
enum Stats {}
44

55
extension Stats {
6-
// Maximum allowed standard deviation is 5% of the median runtime
7-
static let maxAllowedStdev = 0.05
6+
// Maximum allowed standard deviation is 7.5% of the median runtime
7+
static let maxAllowedStdev = 0.075
88

99
static func tTest(_ a: Measurement, _ b: Measurement) -> Bool {
1010
// Student's t-test

Sources/_StringProcessing/Engine/MEBuiltins.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension Processor {
1515
isStrictASCII: Bool,
1616
isScalarSemantics: Bool
1717
) -> Bool {
18-
guard let next = input._matchBuiltinCC(
18+
guard let next = input.matchBuiltinCC(
1919
cc,
2020
at: currentPosition,
2121
isInverted: isInverted,
@@ -123,7 +123,7 @@ extension Processor {
123123
extension String {
124124
// TODO: Should the below have a `limitedBy` parameter?
125125

126-
func _matchAnyNonNewline(
126+
func matchAnyNonNewline(
127127
at currentPosition: String.Index,
128128
isScalarSemantics: Bool
129129
) -> String.Index? {
@@ -145,7 +145,7 @@ extension String {
145145
}
146146

147147
@inline(__always)
148-
func _quickMatchAnyNonNewline(
148+
private func _quickMatchAnyNonNewline(
149149
at currentPosition: String.Index,
150150
isScalarSemantics: Bool
151151
) -> QuickResult<String.Index?> {
@@ -165,7 +165,7 @@ extension String {
165165
}
166166

167167
@inline(never)
168-
func _thoroughMatchAnyNonNewline(
168+
private func _thoroughMatchAnyNonNewline(
169169
at currentPosition: String.Index,
170170
isScalarSemantics: Bool
171171
) -> String.Index? {
@@ -187,7 +187,7 @@ extension String {
187187
// TODO: Should the below have a `limitedBy` parameter?
188188

189189
// Mentioned in ProgrammersManual.md, update docs if redesigned
190-
func _matchBuiltinCC(
190+
func matchBuiltinCC(
191191
_ cc: _CharacterClassModel.Representation,
192192
at currentPosition: String.Index,
193193
isInverted: Bool,
@@ -222,7 +222,7 @@ extension String {
222222

223223
// Mentioned in ProgrammersManual.md, update docs if redesigned
224224
@inline(__always)
225-
func _quickMatchBuiltinCC(
225+
private func _quickMatchBuiltinCC(
226226
_ cc: _CharacterClassModel.Representation,
227227
at currentPosition: String.Index,
228228
isInverted: Bool,
@@ -240,7 +240,7 @@ extension String {
240240

241241
// Mentioned in ProgrammersManual.md, update docs if redesigned
242242
@inline(never)
243-
func _thoroughMatchBuiltinCC(
243+
private func _thoroughMatchBuiltinCC(
244244
_ cc: _CharacterClassModel.Representation,
245245
at currentPosition: String.Index,
246246
isInverted: Bool,

Sources/_StringProcessing/Engine/MEQuantify.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
extension Processor {
22
func _doQuantifyMatch(_ payload: QuantifyPayload) -> Input.Index? {
3-
// FIXME: is the below updated for scalar semantics?
3+
// TODO: This optimization is only enabled for grapheme cluster semantics,
4+
// we want these for scalar semantics as well.
5+
46
switch payload.type {
57
case .bitset:
68
return input.matchBitset(
7-
registers[payload.bitset], at: currentPosition, limitedBy: end)
9+
registers[payload.bitset],
10+
at: currentPosition,
11+
limitedBy: end,
12+
isScalarSemantics: false)
813
case .asciiChar:
914
return input.matchScalar(
1015
UnicodeScalar.init(_value: UInt32(payload.asciiChar)),
1116
at: currentPosition,
1217
limitedBy: end,
13-
boundaryCheck: true)
18+
boundaryCheck: true,
19+
isCaseInsensitive: false)
1420
case .builtin:
1521
// FIXME: bounds check? endIndex or end?
1622

1723
// We only emit .quantify if it consumes a single character
18-
return input._matchBuiltinCC(
24+
return input.matchBuiltinCC(
1925
payload.builtin,
2026
at: currentPosition,
2127
isInverted: payload.builtinIsInverted,
@@ -29,7 +35,7 @@ extension Processor {
2935
return input.index(after: currentPosition)
3036
}
3137

32-
return input._matchAnyNonNewline(
38+
return input.matchAnyNonNewline(
3339
at: currentPosition, isScalarSemantics: false)
3440
}
3541
}
@@ -41,7 +47,7 @@ extension Processor {
4147
var trips = 0
4248
var extraTrips = payload.extraTrips
4349
var savePoint = startQuantifierSavePoint()
44-
50+
4551
while true {
4652
if trips >= payload.minTrips {
4753
if extraTrips == 0 { break }

0 commit comments

Comments
 (0)