summaryrefslogtreecommitdiff
path: root/read.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2011-05-02 00:18:06 +0000
committerPaul Smith <psmith@gnu.org>2011-05-02 00:18:06 +0000
commita81ee5209b97564ce9c2d87f8842c3473fd72490 (patch)
tree2364c14a679fb272e66dbf381c81c8a138389d83 /read.c
parent15a79d723de278d76737b5cbb8d7a1afbe72de7b (diff)
downloadgunmake-a81ee5209b97564ce9c2d87f8842c3473fd72490.tar.gz
Avoid invoking glob() unless the filename has potential globbing
characters in it, for performance improvements.
Diffstat (limited to 'read.c')
-rw-r--r--read.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/read.c b/read.c
index 299c2e5..3f72326 100644
--- 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)