@@ -145,11 +145,16 @@ append_to_file() {
145
145
146
146
make_dir_recursive () {
147
147
local _dir=" $1 "
148
- local _line=" $ umask 022 && mkdir -p \" $_dir \" "
149
- umask 022 && mkdir -p " $_dir "
150
- local _retval=$?
151
- log_line " $_line "
152
- return $_retval
148
+ # Skip if the last invocation of make_dir_recursive had the same argument
149
+ if ! [ " $_dir " = " ${_make_dir_recursive_cached_key:- } " ]
150
+ then
151
+ _make_dir_recursive_cached_key=" $_dir "
152
+ local _line=" $ umask 022 && mkdir -p \" $_dir \" "
153
+ umask 022 && mkdir -p " $_dir "
154
+ local _retval=$?
155
+ log_line " $_line "
156
+ return $_retval
157
+ fi
153
158
}
154
159
155
160
putvar () {
@@ -304,19 +309,30 @@ absolutify() {
304
309
local file_path=" $1 "
305
310
local file_path_dirname=" ${file_path%/* } "
306
311
local file_path_basename=" ${file_path##*/ } "
307
- local file_abs_path=" $( abs_path " $file_path_dirname " ) "
312
+ abs_path_cached " $file_path_dirname "
313
+ local file_abs_path=" $abs_path_cached_retval "
308
314
local file_path=" $file_abs_path /$file_path_basename "
309
315
# This is the return value
310
316
RETVAL=" $file_path "
311
317
}
312
318
313
319
# Prints the absolute path of a directory to stdout
314
320
abs_path () {
321
+ abs_path_cached " $@ "
322
+ printf %s " $abs_path_cached_retval "
323
+ }
324
+
325
+ abs_path_cached () {
315
326
local path=" $1 "
316
- # Unset CDPATH because it causes havok: it makes the destination unpredictable
317
- # and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
318
- # for good measure.
319
- (unset CDPATH && cd " $path " > /dev/null && pwd)
327
+ # Update return value only if the argument differs from the last invocation
328
+ if ! [ " $path " = " ${_abs_path_cached_key:- } " ]
329
+ then
330
+ _abs_path_cached_key=" $path "
331
+ # Unset CDPATH because it causes havok: it makes the destination unpredictable
332
+ # and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
333
+ # for good measure.
334
+ abs_path_cached_retval=" $( unset CDPATH && cd " $path " > /dev/null && pwd) "
335
+ fi
320
336
}
321
337
322
338
uninstall_legacy () {
0 commit comments