libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Followup patch: compute dirname and basename at once, when both are need


From: Charles Wilson
Subject: Followup patch: compute dirname and basename at once, when both are needed
Date: Thu, 12 Jul 2007 02:33:42 -0400
User-agent: Thunderbird 1.5.0.12 (Windows/20070509)

When reviewing one of my earlier patches, Ralf said:
Side note: there should be a function that does both dirname and
basename at once, for speed.  (Not in this patch, but later.)
Another instance below.

This patch adds that new function, and adjusts several locations to take advantage of it. Tested on cygwin and linux with no regressions.

I deliberately re-used the same return variables as func_dirname() and func_basename() to minimize ripple, and so that this combo function could be a drop-in replacement for calls to the two separate funcs.

ChangeLog:

2007-07-11  Charles Wilson  <...>

        * libltdl/m4/libtool.m4 (func_dirname_and_basename): New
        function
        * libltdl/config/ltmain.m4sh (func_ltwrapper_scriptname):
        Call it.  Also, take advantage of missed optimization using
        func_dirname's additional arguments.
        (func_mode_compile): Call it.
        (func_mode_install): Call it.
        (func_mode_link): Call it.

--
Chuck

Index: libltdl/config/ltmain.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/config/ltmain.m4sh,v
retrieving revision 1.83
diff -u -r1.83 ltmain.m4sh
--- libltdl/config/ltmain.m4sh  7 Jul 2007 05:09:10 -0000       1.83
+++ libltdl/config/ltmain.m4sh  12 Jul 2007 03:04:20 -0000
@@ -692,14 +692,9 @@
 {
     func_ltwrapper_scriptname_result=""
     if func_ltwrapper_executable_p "$1"; then
-       func_dirname "$1"
-       func_basename "$1"
+       func_dirname_and_basename "$1" "" "."
        func_stripname '' '.exe' "$func_basename_result"
-       if test -z "$func_dirname_result"; then
-           
func_ltwrapper_scriptname_result="./$objdir/${func_stripname_result}_ltshwrapper"
-       else
-           
func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
-       fi
+       
func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
     fi
 }
 
@@ -1422,9 +1417,8 @@
     test "X$libobj" != "X$func_quote_for_eval_result" \
       && $ECHO "X$libobj" | $GREP '[@:>@~#^*{};<>?"'"'"'       &()|`$@<:@]' \
       && func_warning "libobj name \`$libobj' may not contain shell special 
characters."
-    func_basename "$obj"
+    func_dirname_and_basename "$obj" "/" ""
     objname="$func_basename_result"
-    func_dirname "$obj" "/" ""
     xdir="$func_dirname_result"
     lobj=${xdir}$objdir/$objname
 
@@ -1921,9 +1915,8 @@
       destdir="$dest"
       destname=
     else
-      func_dirname "$dest" "" "."
+      func_dirname_and_basename "$dest" "" "."
       destdir="$func_dirname_result"
-      func_basename "$dest"
       destname="$func_basename_result"
 
       # Not a directory, so check to see that there is only one file specified.
@@ -6785,13 +6778,9 @@
        esac
        case $host in
          *cygwin* | *mingw* )
-           func_basename "$output"
+           func_dirname_and_basename "$output" "" "."
            output_name=$func_basename_result
-           func_dirname "$output"
            output_path=$func_dirname_result
-           if test -z "$output_path"; then
-             output_path=.
-           fi
            cwrappersource="$output_path/$objdir/lt-$output_name.c"
            cwrapper="$output_path/$output_name.exe"
            $RM $cwrappersource $cwrapper
Index: libltdl/m4/libtool.m4
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/m4/libtool.m4,v
retrieving revision 1.111
diff -u -r1.111 libtool.m4
--- libltdl/m4/libtool.m4       3 Jul 2007 05:09:40 -0000       1.111
+++ libltdl/m4/libtool.m4       12 Jul 2007 03:04:24 -0000
@@ -7056,6 +7056,27 @@
   func_basename_result="${1##*/}"
 }
 
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result 
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+  func_basename_result="${1##*/}"
+}
+
 # func_stripname prefix suffix name
 # strip PREFIX and SUFFIX off of NAME.
 # PREFIX and SUFFIX must not contain globbing or regex special

reply via email to

[Prev in Thread] Current Thread [Next in Thread]