[git commit] ash: if using libc glob(), skip it if no metachars are in word
Denys Vlasenko
vda.linux at googlemail.com
Sun Oct 30 17:41:01 UTC 2016
commit: https://git.busybox.net/busybox/commit/?id=d4f3db9427c443b2709fc9a00bc46d8a71be806b
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
This saves making tons of pointless stat() calls
function old new delta
expandarg 888 921 +33
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
shell/ash.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/shell/ash.c b/shell/ash.c
index d617168..ecd2146 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -7047,6 +7047,21 @@ expandmeta(struct strlist *str /*, int flag*/)
if (fflag)
goto nometa;
+
+ /* Avoid glob() (and thus, stat() et al) for words like "echo" */
+ p = str->text;
+ while (*p) {
+ if (*p == '*')
+ goto need_glob;
+ if (*p == '?')
+ goto need_glob;
+ if (*p == '[')
+ goto need_glob;
+ p++;
+ }
+ goto nometa;
+
+ need_glob:
INT_OFF;
p = preglob(str->text, RMESCAPE_ALLOC | RMESCAPE_HEAP);
// GLOB_NOMAGIC (GNU): if no *?[ chars in pattern, return it even if no match
More information about the busybox-cvs
mailing list