]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Avoid invoking glob() unless the filename has potential globbing
authorPaul Smith <psmith@gnu.org>
Mon, 2 May 2011 00:18:06 +0000 (00:18 +0000)
committerPaul Smith <psmith@gnu.org>
Mon, 2 May 2011 00:18:06 +0000 (00:18 +0000)
characters in it, for performance improvements.

ChangeLog
read.c

index e365f6bb2206d49eefcd4a15ddae00e5a4509cd4..06f7fde905a92fff7f06ec37937a7afdd9a524ce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-05-01  Paul Smith  <psmith@gnu.org>
+
+       * read.c (parse_file_seq): Don't try to invoke glob() unless there
+       are potential wildcard characters in the filename.  Performance
+       enhancement suggested by Michael Meeks <michael.meeks@novell.com>
+
 2011-04-29 Boris Kolpackov  <boris@codesynthesis.com>
 
        * read.c (eval_makefile): Delay caching of the file name until after
diff --git a/read.c b/read.c
index 299c2e5d47ab1bf52f20e86da73a6e231f4b4fbb..3f72326e7d537c585c1ef9da0c8566f7b461aa6d 100644 (file)
--- a/read.c
+++ b/read.c
@@ -2901,6 +2901,7 @@ parse_file_seq (char **stringp, unsigned int size, int stopchar,
       const char *name;
       const char **nlist = 0;
       char *tildep = 0;
+      int globme = 1;
 #ifndef NO_ARCHIVES
       char *arname = 0;
       char *memname = 0;
@@ -3109,32 +3110,40 @@ parse_file_seq (char **stringp, unsigned int size, int stopchar,
        }
 #endif /* !NO_ARCHIVES */
 
-      switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
-       {
-       case GLOB_NOSPACE:
-         fatal (NILF, _("virtual memory exhausted"));
+      /* glob() is expensive: don't call it unless we need to.  */
+      if (!(flags & PARSEFS_EXISTS) || strpbrk (name, "?*[") == NULL)
+        {
+          globme = 0;
+          i = 1;
+          nlist = &name;
+        }
+      else
+        switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
+          {
+          case GLOB_NOSPACE:
+            fatal (NILF, _("virtual memory exhausted"));
 
-       case 0:
-          /* Success.  */
-          i = gl.gl_pathc;
-          nlist = (const char **)gl.gl_pathv;
-          break;
+          case 0:
+            /* Success.  */
+            i = gl.gl_pathc;
+            nlist = (const char **)gl.gl_pathv;
+            break;
 
-        case GLOB_NOMATCH:
-          /* If we want only existing items, skip this one.  */
-          if (flags & PARSEFS_EXISTS)
-            {
-              i = 0;
-              break;
-            }
-          /* FALLTHROUGH */
+          case GLOB_NOMATCH:
+            /* If we want only existing items, skip this one.  */
+            if (flags & PARSEFS_EXISTS)
+              {
+                i = 0;
+                break;
+              }
+            /* FALLTHROUGH */
 
-       default:
-          /* By default keep this name.  */
-          i = 1;
-          nlist = &name;
-          break;
-       }
+          default:
+            /* By default keep this name.  */
+            i = 1;
+            nlist = &name;
+            break;
+          }
 
       /* For each matched element, add it to the list.  */
       while (i-- > 0)
@@ -3174,7 +3183,8 @@ parse_file_seq (char **stringp, unsigned int size, int stopchar,
 #endif /* !NO_ARCHIVES */
           NEWELT (concat (2, prefix, nlist[i]));
 
-      globfree (&gl);
+      if (globme)
+        globfree (&gl);
 
 #ifndef NO_ARCHIVES
       if (arname)