From 81cbe499384db4e43e75d73c0f1ca8c75a770fa5 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 21 Nov 2010 00:16:37 -0800 Subject: [PATCH] minimal/do: write my own replacements for dirname and basename. This greatly reduces the number of fork+exec calls, so in particular, t/curse/all.do now runs much faster: /bin/sh (bash): was 5.9s, now 2.2s /bin/dash: was 3.2s, now 1.1s Obviously improving the speed of minimal/do doesn't really matter, except that it makes a good benchmark to compare the "real" redo against. So far it's losing badly: 5.4s. --- minimal/do | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/minimal/do b/minimal/do index e099c28..cf0ccec 100755 --- a/minimal/do +++ b/minimal/do @@ -16,6 +16,21 @@ if [ -z "$DO_BUILT" ]; then fi +_dirsplit() +{ + OLDIFS="$IFS" + IFS=/ + set -- $1 + IFS="$OLDIFS" + dir="" + while [ $# -gt 1 ]; do + dir="$dir$1/" + shift + done + base="$1" +} + + _do() { DIR="$1" @@ -61,10 +76,8 @@ redo() if [ -e "$i/." ]; then i="$i/all" fi - D="$(dirname "$i")/" - [ "$D" = "./" ] && D="" - B="$(basename "$i")" - ( cd "$D" && _do "$D" "$B" ) || exit $? + _dirsplit "$i" + ( cd "$dir" && _do "$dir" "$base" ) || exit $? done }