@@ -20,14 +20,15 @@ import Darwin
20
20
public let StringMatch = BenchmarkInfo (
21
21
name: " StringMatch " ,
22
22
runFunction: run_StringMatch,
23
- tags: [ . validation, . api, . String] )
23
+ tags: [ . validation, . api, . String] ,
24
+ legacyFactor: 100 )
24
25
25
26
/* match: search for regexp anywhere in text */
26
27
func match( regexp: String , text: String ) -> Bool {
27
28
if regexp. first == " ^ " {
28
29
return matchHere ( regexp. dropFirst ( ) , text [ ... ] )
29
30
}
30
-
31
+
31
32
var idx = text. startIndex
32
33
while true { // must look even if string is empty
33
34
if matchHere ( regexp [ ... ] , text [ idx..< text. endIndex] ) {
@@ -37,7 +38,7 @@ func match(regexp: String, text: String) -> Bool {
37
38
// do while sufficed in the original C version...
38
39
text. formIndex ( after: & idx)
39
40
} // while idx++ != string.endIndex
40
-
41
+
41
42
return false
42
43
}
43
44
@@ -46,19 +47,19 @@ func matchHere(_ regexp: Substring, _ text: Substring) -> Bool {
46
47
if regexp. isEmpty {
47
48
return true
48
49
}
49
-
50
+
50
51
if let c = regexp. first, regexp. dropFirst ( ) . first == " * " {
51
52
return matchStar ( c, regexp. dropFirst ( 2 ) , text)
52
53
}
53
-
54
+
54
55
if regexp. first == " $ " && regexp. dropFirst ( ) . isEmpty {
55
56
return text. isEmpty
56
57
}
57
-
58
+
58
59
if let tc = text. first, let rc = regexp. first, rc == " . " || tc == rc {
59
60
return matchHere ( regexp. dropFirst ( ) , text. dropFirst ( ) )
60
61
}
61
-
62
+
62
63
return false
63
64
}
64
65
@@ -87,10 +88,9 @@ let tests: KeyValuePairs = [
87
88
88
89
@inline ( never)
89
90
public func run_StringMatch( _ N: Int ) {
90
- for _ in 1 ... N*100 {
91
+ for _ in 1 ... N {
91
92
for (regex, text) in tests {
92
93
_ = match ( regexp: regex, text: text)
93
94
}
94
95
}
95
96
}
96
-
0 commit comments