Skip to content

Commit 48d1558

Browse files
committed
[benchmark][Gardening] Nested test filter funcs
Refactored `filterTests` to use two nested functions that better reveal the underlying logic.
1 parent bfa198b commit 48d1558

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

benchmark/utils/DriverUtils.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,21 @@ struct TestConfig {
184184
skipTags: Set<BenchmarkCategory>
185185
) -> [(index: String, info: BenchmarkInfo)] {
186186
let indices = Dictionary(uniqueKeysWithValues:
187-
zip(registeredBenchmarks.sorted().map{ $0.name },
187+
zip(registeredBenchmarks.sorted().map { $0.name },
188188
(1...).lazy.map { String($0) } ))
189-
let benchmarkNamesOrIndices = Set(filters)
189+
let specifiedTests = Set(filters)
190190

191-
return registeredBenchmarks.filter { benchmark in
192-
if benchmarkNamesOrIndices.isEmpty {
193-
return benchmark.tags.isSuperset(of: tags) &&
194-
benchmark.tags.isDisjoint(with: skipTags)
195-
} else {
196-
return benchmarkNamesOrIndices.contains(benchmark.name) ||
197-
benchmarkNamesOrIndices.contains(indices[benchmark.name]!)
198-
}
199-
}.map { (index: indices[$0.name]!, info: $0) }
191+
func byTags(b: BenchmarkInfo) -> Bool {
192+
return b.tags.isSuperset(of: tags) &&
193+
b.tags.isDisjoint(with: skipTags)
194+
}
195+
func byNamesOrIndices(b: BenchmarkInfo) -> Bool {
196+
return specifiedTests.contains(b.name) ||
197+
specifiedTests.contains(indices[b.name]!)
198+
} // !! "All registeredBenchmarks have been assigned an index"
199+
return registeredBenchmarks
200+
.filter(filters.isEmpty ? byTags : byNamesOrIndices)
201+
.map { (index: indices[$0.name]!, info: $0) }
200202
}
201203
}
202204

0 commit comments

Comments
 (0)