You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
4.5 KiB
154 lines
4.5 KiB
# --- SDE-COPYRIGHT-NOTE-BEGIN --- |
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch. |
|
# |
|
# Filename: package/.../make/make-3.82-0004-improve-glob-speed.patch |
|
# Copyright (C) 2012 The OpenSDE Project |
|
# |
|
# More information can be found in the files COPYING and README. |
|
# |
|
# This patch file is dual-licensed. It is available under the license the |
|
# patched project is licensed under, as long as it is an OpenSource license |
|
# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms |
|
# of the GNU General Public License as published by the Free Software |
|
# Foundation; either version 2 of the License, or (at your option) any later |
|
# version. |
|
# --- SDE-COPYRIGHT-NOTE-END --- |
|
|
|
From b905f2002daaacc62cc5c083ebc6f7ba787a793e Mon Sep 17 00:00:00 2001 |
|
From: Christian Wiese <chris@opensde.org> |
|
Date: Mon, 22 Oct 2012 17:58:00 +0200 |
|
Subject: [PATCH] improve glob speed |
|
|
|
ChangeLog: |
|
|
|
2011-05-07 Paul Smith <psmith@gnu.org> |
|
|
|
* read.c (parse_file_seq): Ensure existence checks use glob(). |
|
|
|
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> |
|
|
|
tests/Changelog: |
|
|
|
2011-05-07 Paul Smith <psmith@gnu.org> |
|
|
|
* scripts/functions/wildcard: Verify wildcard used to test for |
|
file existence/non-existence. |
|
--- |
|
read.c | 58 ++++++++++++++++++++++--------------- |
|
tests/scripts/functions/wildcard | 12 ++++++++ |
|
2 files changed, 46 insertions(+), 24 deletions(-) |
|
|
|
diff --git a/read.c b/read.c |
|
index 9dfd4ea..8587e85 100644 |
|
--- a/read.c |
|
+++ b/read.c |
|
@@ -2904,6 +2904,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; |
|
@@ -3112,32 +3113,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) |
|
@@ -3177,7 +3186,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) |
|
diff --git a/tests/scripts/functions/wildcard b/tests/scripts/functions/wildcard |
|
index 2841f5d..bcd84ad 100644 |
|
--- a/tests/scripts/functions/wildcard |
|
+++ b/tests/scripts/functions/wildcard |
|
@@ -88,4 +88,16 @@ all: ; @echo $(wildcard xz--y*.7) |
|
!, |
|
'', "\n"); |
|
|
|
+# TEST #5: wildcard used to verify file existence |
|
+ |
|
+touch('xxx.yyy'); |
|
+ |
|
+run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!, |
|
+ '', "file=xxx.yyy\n"); |
|
+ |
|
+unlink('xxx.yyy'); |
|
+ |
|
+run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!, |
|
+ '', "file=\n"); |
|
+ |
|
1; |
|
-- |
|
1.7.2.3 |
|
|
|
|