From daf76c27c146598c2deba15694c6cd01b2cd82a6 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Thu, 16 Mar 2017 12:25:17 -0400 Subject: [PATCH] bats: Convert abs_dirname to use `printf -v` Under Bash 3.2.57(1)-release and 4.4.12(1)-release on a MacBook Pro with a 2.9GHz Intel Core i5 CPU and 8GB 1867MHz DDR3 RAM, this shaves off O(0.1s) from the current test suite. Before the change: 46 tests, 0 failures real 0m3.983s user 0m2.320s sys 0m1.241s After the change: real 0m3.861s user 0m2.276s sys 0m1.174s --- libexec/bats | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libexec/bats b/libexec/bats index 8129050..5e90a9e 100755 --- a/libexec/bats +++ b/libexec/bats @@ -51,7 +51,7 @@ abs_dirname() { path="$(resolve_link "$name")" done - pwd + printf -v "$2" -- '%s' "$PWD" cd "$cwd" } @@ -63,9 +63,12 @@ expand_path() { } || echo "$1" } -BATS_LIBEXEC="$(abs_dirname "$0")" -export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")" -export BATS_CWD="$(abs_dirname .)" +abs_dirname "$0" 'BATS_LIBEXEC' +abs_dirname "$BATS_LIBEXEC" 'BATS_PREFIX' +abs_dirname '.' 'BATS_CWD' + +export BATS_PREFIX +export BATS_CWD export PATH="$BATS_LIBEXEC:$PATH" options=()