Blame SOURCES/make-3.82-expensive_glob.patch

71dafe
Index: read.c
71dafe
===================================================================
71dafe
RCS file: /sources/make/make/read.c,v
71dafe
retrieving revision 1.198
71dafe
retrieving revision 1.200
71dafe
diff -u -r1.198 -r1.200
71dafe
--- read.c	29 Apr 2011 15:27:39 -0000	1.198
71dafe
+++ read.c	7 May 2011 14:36:12 -0000	1.200
71dafe
@@ -2901,6 +2901,7 @@
71dafe
       const char *name;
71dafe
       const char **nlist = 0;
71dafe
       char *tildep = 0;
71dafe
+      int globme = 1;
71dafe
 #ifndef NO_ARCHIVES
71dafe
       char *arname = 0;
71dafe
       char *memname = 0;
71dafe
@@ -3109,32 +3110,40 @@
71dafe
 	}
71dafe
 #endif /* !NO_ARCHIVES */
71dafe
 
71dafe
-      switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
71dafe
-	{
71dafe
-	case GLOB_NOSPACE:
71dafe
-	  fatal (NILF, _("virtual memory exhausted"));
71dafe
-
71dafe
-	case 0:
71dafe
-          /* Success.  */
71dafe
-          i = gl.gl_pathc;
71dafe
-          nlist = (const char **)gl.gl_pathv;
71dafe
-          break;
71dafe
-
71dafe
-        case GLOB_NOMATCH:
71dafe
-          /* If we want only existing items, skip this one.  */
71dafe
-          if (flags & PARSEFS_EXISTS)
71dafe
-            {
71dafe
-              i = 0;
71dafe
-              break;
71dafe
-            }
71dafe
-          /* FALLTHROUGH */
71dafe
-
71dafe
-	default:
71dafe
-          /* By default keep this name.  */
71dafe
+      /* glob() is expensive: don't call it unless we need to.  */
71dafe
+      if (!(flags & PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL)
71dafe
+        {
71dafe
+          globme = 0;
71dafe
           i = 1;
71dafe
           nlist = &nam;;
71dafe
-          break;
71dafe
-	}
71dafe
+        }
71dafe
+      else
71dafe
+        switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
71dafe
+          {
71dafe
+          case GLOB_NOSPACE:
71dafe
+            fatal (NILF, _("virtual memory exhausted"));
71dafe
+
71dafe
+          case 0:
71dafe
+            /* Success.  */
71dafe
+            i = gl.gl_pathc;
71dafe
+            nlist = (const char **)gl.gl_pathv;
71dafe
+            break;
71dafe
+
71dafe
+          case GLOB_NOMATCH:
71dafe
+            /* If we want only existing items, skip this one.  */
71dafe
+            if (flags & PARSEFS_EXISTS)
71dafe
+              {
71dafe
+                i = 0;
71dafe
+                break;
71dafe
+              }
71dafe
+            /* FALLTHROUGH */
71dafe
+
71dafe
+          default:
71dafe
+            /* By default keep this name.  */
71dafe
+            i = 1;
71dafe
+            nlist = &nam;;
71dafe
+            break;
71dafe
+          }
71dafe
 
71dafe
       /* For each matched element, add it to the list.  */
71dafe
       while (i-- > 0)
71dafe
@@ -3174,7 +3183,8 @@
71dafe
 #endif /* !NO_ARCHIVES */
71dafe
           NEWELT (concat (2, prefix, nlist[i]));
71dafe
 
71dafe
-      globfree (&gl);
71dafe
+      if (globme)
71dafe
+        globfree (&gl);
71dafe
 
71dafe
 #ifndef NO_ARCHIVES
71dafe
       if (arname)
71dafe
Index: tests/scripts/functions/wildcard
71dafe
===================================================================
71dafe
RCS file: /sources/make/make/tests/scripts/functions/wildcard,v
71dafe
retrieving revision 1.6
71dafe
retrieving revision 1.7
71dafe
diff -u -r1.6 -r1.7
71dafe
--- tests/scripts/functions/wildcard	13 Jun 2009 21:21:49 -0000	1.6
71dafe
+++ tests/scripts/functions/wildcard	7 May 2011 14:36:11 -0000	1.7
71dafe
@@ -88,4 +88,16 @@
71dafe
 !,
71dafe
               '', "\n");
71dafe
 
71dafe
+# TEST #5: wildcard used to verify file existence
71dafe
+
71dafe
+touch('xxx.yyy');
71dafe
+
71dafe
+run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!,
71dafe
+              '', "file=xxx.yyy\n");
71dafe
+
71dafe
+unlink('xxx.yyy');
71dafe
+
71dafe
+run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!,
71dafe
+              '', "file=\n");
71dafe
+
71dafe
 1;