[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: substantial 'glob' speedup ...
From: |
Michael Meeks |
Subject: |
Re: substantial 'glob' speedup ... |
Date: |
Fri, 08 Apr 2011 17:08:31 +0100 |
Hi Paul,
On Thu, 2011-04-07 at 08:53 -0400, Paul Smith wrote:
> That's interesting. I wonder why the glob expansion is so inefficient;
Oh - because it is also testing for existence :-) and also doing a
chunk of dynamic memory management with it I suspect.
> I would expect it to do the same kinds of checks that you're doing (that
> is, basically be a string-walk unless a glob character is found).
> Why not just use strpbrk()?
I had no idea it existed ? :-) it would be preferable of course. I
tried a somewhat differet approach (patch appended).
before orig. patch GLOB_NOMAGIC
real 0m5.795s 0m2.634s 0m3.569s
user 0m3.513s 0m2.526s 0m3.450s
sys 0m2.274s 0m0.101s 0m0.113s
But but apparently the malloc / free overhead from our 700k 'glob'
calls burns rather a lot of extra CPU here, the patch is slightly
simpler (though hardly if you use strpbrk).
So - I'd rather prefer my original; with the glob scope indented to
avoid the glob_free having an ugly condition, and using strpbrk; but
that's just me.
HTH !
Michael.
diff --git a/read.c b/read.c
index a3ad88e..81ca7cd 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 glob_flags;
#ifndef NO_ARCHIVES
char *arname = 0;
char *memname = 0;
@@ -3112,7 +3113,10 @@ parse_file_seq (char **stringp, unsigned int size, int
stopchar,
}
#endif /* !NO_ARCHIVES */
- switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
+ glob_flags = GLOB_NOSORT|GLOB_ALTDIRFUNC;
+ if (!(flags & PARSEFS_EXISTS))
+ glob_flags |= GLOB_NOMAGIC;
+ switch (glob (name, glob_flags, NULL, &gl))
{
case GLOB_NOSPACE:
fatal (NILF, _("virtual memory exhausted"));
--
address@hidden <><, Pseudo Engineer, itinerant idiot