Skip to content

Commit 38cf10e

Browse files
committed
wip: shorter
1 parent 88283b7 commit 38cf10e

File tree

2 files changed

+20
-33
lines changed

2 files changed

+20
-33
lines changed

Sources/_StringProcessing/Engine/MEBuiltins.swift

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,24 @@ extension Processor {
3434
isStrictASCII: Bool,
3535
isScalarSemantics: Bool
3636
) -> Input.Index? {
37-
switch _quickMatchBuiltinCC(
37+
if case .definite(let result) = _quickMatchBuiltinCC(
3838
cc,
3939
isInverted: isInverted,
4040
isStrictASCII: isStrictASCII,
4141
isScalarSemantics: isScalarSemantics
4242
) {
43-
case .no:
44-
return nil
45-
case .yes(let next):
46-
return next
47-
case .maybe:
48-
return _slowMatchBuiltinCC(
49-
cc,
50-
isInverted: isInverted,
51-
isStrictASCII: isStrictASCII,
52-
isScalarSemantics: isScalarSemantics)
43+
assert(result == _thoroughMatchBuiltinCC(
44+
cc,
45+
isInverted: isInverted,
46+
isStrictASCII: isStrictASCII,
47+
isScalarSemantics: isScalarSemantics))
48+
return result
5349
}
50+
return _thoroughMatchBuiltinCC(
51+
cc,
52+
isInverted: isInverted,
53+
isStrictASCII: isStrictASCII,
54+
isScalarSemantics: isScalarSemantics)
5455
}
5556

5657
@inline(__always)
@@ -59,23 +60,17 @@ extension Processor {
5960
isInverted: Bool,
6061
isStrictASCII: Bool,
6162
isScalarSemantics: Bool
62-
) -> QuickResult<Input.Index> {
63+
) -> QuickResult<Input.Index?> {
6364
guard let (next, result) = input._quickMatch(
6465
cc, at: currentPosition, isScalarSemantics: isScalarSemantics
6566
) else {
66-
return .maybe
67+
return .unknown
6768
}
68-
let idx = result == isInverted ? nil : next
69-
assert(idx == _slowMatchBuiltinCC(
70-
cc,
71-
isInverted: isInverted,
72-
isStrictASCII: isStrictASCII,
73-
isScalarSemantics: isScalarSemantics))
74-
return .definite(idx)
69+
return .definite(result == isInverted ? nil : next)
7570
}
7671

7772
@inline(never)
78-
func _slowMatchBuiltinCC(
73+
func _thoroughMatchBuiltinCC(
7974
_ cc: _CharacterClassModel.Representation,
8075
isInverted: Bool,
8176
isStrictASCII: Bool,

Sources/_StringProcessing/StringExtras.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,11 @@ extension String {
128128

129129
}
130130

131-
/// An enum for quick-check functions, which could return a yes, no, or maybe
132-
/// result.
131+
/// An enum for quick-check functions, which could return an answer or indefinite.
132+
/// We use a separate type because often the answer itself is optional.
133133
enum QuickResult<R> {
134-
case yes(_ r: R)
135-
case no
136-
case maybe
137-
138-
static func definite(_ r: R?) -> QuickResult {
139-
if let r = r {
140-
return .yes(r)
141-
}
142-
return .no
143-
}
134+
case definite(_ r: R)
135+
case unknown
144136
}
145137

146138

0 commit comments

Comments
 (0)