Contents of /trunk/make/patches/make-3.82-expensive-glob.patch
Parent Directory | Revision Log
Revision 2179 -
(show annotations)
(download)
Wed May 22 12:31:00 2013 UTC (11 years, 1 month ago) by niro
File size: 3106 byte(s)
Wed May 22 12:31:00 2013 UTC (11 years, 1 month ago) by niro
File size: 3106 byte(s)
-more patches from upstream
1 | Index: read.c |
2 | =================================================================== |
3 | RCS file: /sources/make/make/read.c,v |
4 | retrieving revision 1.198 |
5 | retrieving revision 1.200 |
6 | diff -u -r1.198 -r1.200 |
7 | --- read.c 29 Apr 2011 15:27:39 -0000 1.198 |
8 | +++ read.c 7 May 2011 14:36:12 -0000 1.200 |
9 | @@ -2901,6 +2901,7 @@ |
10 | const char *name; |
11 | const char **nlist = 0; |
12 | char *tildep = 0; |
13 | + int globme = 1; |
14 | #ifndef NO_ARCHIVES |
15 | char *arname = 0; |
16 | char *memname = 0; |
17 | @@ -3109,32 +3110,40 @@ |
18 | } |
19 | #endif /* !NO_ARCHIVES */ |
20 | |
21 | - switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl)) |
22 | - { |
23 | - case GLOB_NOSPACE: |
24 | - fatal (NILF, _("virtual memory exhausted")); |
25 | - |
26 | - case 0: |
27 | - /* Success. */ |
28 | - i = gl.gl_pathc; |
29 | - nlist = (const char **)gl.gl_pathv; |
30 | - break; |
31 | - |
32 | - case GLOB_NOMATCH: |
33 | - /* If we want only existing items, skip this one. */ |
34 | - if (flags & PARSEFS_EXISTS) |
35 | - { |
36 | - i = 0; |
37 | - break; |
38 | - } |
39 | - /* FALLTHROUGH */ |
40 | - |
41 | - default: |
42 | - /* By default keep this name. */ |
43 | + /* glob() is expensive: don't call it unless we need to. */ |
44 | + if (!(flags & PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL) |
45 | + { |
46 | + globme = 0; |
47 | i = 1; |
48 | nlist = &name; |
49 | - break; |
50 | - } |
51 | + } |
52 | + else |
53 | + switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl)) |
54 | + { |
55 | + case GLOB_NOSPACE: |
56 | + fatal (NILF, _("virtual memory exhausted")); |
57 | + |
58 | + case 0: |
59 | + /* Success. */ |
60 | + i = gl.gl_pathc; |
61 | + nlist = (const char **)gl.gl_pathv; |
62 | + break; |
63 | + |
64 | + case GLOB_NOMATCH: |
65 | + /* If we want only existing items, skip this one. */ |
66 | + if (flags & PARSEFS_EXISTS) |
67 | + { |
68 | + i = 0; |
69 | + break; |
70 | + } |
71 | + /* FALLTHROUGH */ |
72 | + |
73 | + default: |
74 | + /* By default keep this name. */ |
75 | + i = 1; |
76 | + nlist = &name; |
77 | + break; |
78 | + } |
79 | |
80 | /* For each matched element, add it to the list. */ |
81 | while (i-- > 0) |
82 | @@ -3174,7 +3183,8 @@ |
83 | #endif /* !NO_ARCHIVES */ |
84 | NEWELT (concat (2, prefix, nlist[i])); |
85 | |
86 | - globfree (&gl); |
87 | + if (globme) |
88 | + globfree (&gl); |
89 | |
90 | #ifndef NO_ARCHIVES |
91 | if (arname) |
92 | Index: tests/scripts/functions/wildcard |
93 | =================================================================== |
94 | RCS file: /sources/make/make/tests/scripts/functions/wildcard,v |
95 | retrieving revision 1.6 |
96 | retrieving revision 1.7 |
97 | diff -u -r1.6 -r1.7 |
98 | --- tests/scripts/functions/wildcard 13 Jun 2009 21:21:49 -0000 1.6 |
99 | +++ tests/scripts/functions/wildcard 7 May 2011 14:36:11 -0000 1.7 |
100 | @@ -88,4 +88,16 @@ |
101 | !, |
102 | '', "\n"); |
103 | |
104 | +# TEST #5: wildcard used to verify file existence |
105 | + |
106 | +touch('xxx.yyy'); |
107 | + |
108 | +run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!, |
109 | + '', "file=xxx.yyy\n"); |
110 | + |
111 | +unlink('xxx.yyy'); |
112 | + |
113 | +run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!, |
114 | + '', "file=\n"); |
115 | + |
116 | 1; |