Skip to content

Commit 7495e45

Browse files
jbergstroempgrange
authored andcommitted
chore(perf): reduce grep/sed calls in hot path
1 parent 8b7b59d commit 7495e45

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

bash_unit

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,16 @@ run_tests() {
248248

249249
local all_functions=$(set)
250250

251-
local pending_tests=$(echo "$all_functions" | "$GREP" -E '^(pending|todo).* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::')
251+
local pending_tests=$(echo "$all_functions" | "$GREP" -E '^(pending|todo).* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -oE '^[^ ]+')
252+
local matched_tests=$(echo "$all_functions" | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern")
253+
252254
if [[ -n "$skip_pattern" ]]
253255
then
254-
local skipped_tests=$(echo "$all_functions" | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -E "$skip_pattern" | "$SED" -e 's: .*::')
255-
local tests_to_run="$(echo "$all_functions" | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -v -E "$skip_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)"
256+
local skipped_tests=$(echo "$matched_tests" | "$GREP" -E "$skip_pattern" | "$GREP" -oE '^[^ ]+')
257+
local tests_to_run=$(echo "$matched_tests" | "$GREP" -v -E "$skip_pattern" | "$GREP" -oE '^[^ ]+' | maybe_shuffle)
256258
else
257259
local skipped_tests=""
258-
local tests_to_run="$(echo "$all_functions" | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)"
260+
local tests_to_run=$(echo "$matched_tests" | "$GREP" -oE '^[^ ]+' | maybe_shuffle)
259261
fi
260262

261263
local test_count=$(cat "${TEST_COUNT_FILE}")

0 commit comments

Comments
 (0)