Mercurial > gnulib
changeset 17640:aa5bda4ec2ae
fts: avoid unnecessary strlen calls
* lib/fts.c (_D_EXACT_NAMLEN): Remove macro.
(fts_build): Store the length of the dp->d_name entry in a local variable
instead of calling strlen() several times via the above, removed macro.
For 'rm -rf some-dir' with e.g. 1M directory entries, this speeds up the
run by ~4%, and reduces the execution time by about a third if run
via "ltrace -c rm -rf some-dir".
author | Bernhard Voelker <mail@bernhard-voelker.de> |
---|---|
date | Wed, 09 Apr 2014 14:14:08 +0200 |
parents | 18db66e8469e |
children | 019200939aa7 |
files | ChangeLog lib/fts.c |
diffstat | 2 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Apr 03 06:58:48 2014 -0700 +++ b/ChangeLog Wed Apr 09 14:14:08 2014 +0200 @@ -1,3 +1,13 @@ +2014-03-26 Bernhard Voelker <mail@bernhard-voelker.de> + + fts: avoid unnecessary strlen calls + * lib/fts.c (_D_EXACT_NAMLEN): Remove macro. + (fts_build): Store the length of the dp->d_name entry in a local variable + instead of calling strlen() several times via the above, removed macro. + For 'rm -rf some-dir' with e.g. 1M directory entries, this speeds up the + run by ~4%, yet this reduces the execution time by about a third if run + via "ltrace -c rm -rf some-dir". + 2014-03-27 Paul Eggert <eggert@cs.ucla.edu> obstack: Remove ancient NeXTSTEP gcc support conditional
--- a/lib/fts.c Thu Apr 03 06:58:48 2014 -0700 +++ b/lib/fts.c Wed Apr 09 14:14:08 2014 +0200 @@ -79,9 +79,6 @@ #endif #include <dirent.h> -#ifndef _D_EXACT_NAMLEN -# define _D_EXACT_NAMLEN(dirent) strlen ((dirent)->d_name) -#endif #if HAVE_STRUCT_DIRENT_D_TYPE /* True if the type of the directory entry D is known. */ @@ -1447,19 +1444,20 @@ nitems = 0; while (cur->fts_dirp) { bool is_dir; + size_t d_namelen; struct dirent *dp = readdir(cur->fts_dirp); if (dp == NULL) break; if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) continue; - if ((p = fts_alloc (sp, dp->d_name, - _D_EXACT_NAMLEN (dp))) == NULL) + d_namelen = strlen (dp->d_name); + if ((p = fts_alloc (sp, dp->d_name, d_namelen)) == NULL) goto mem1; - if (_D_EXACT_NAMLEN (dp) >= maxlen) { + if (d_namelen >= maxlen) { /* include space for NUL */ oldaddr = sp->fts_path; - if (! fts_palloc(sp, _D_EXACT_NAMLEN (dp) + len + 1)) { + if (! fts_palloc(sp, d_namelen + len + 1)) { /* * No more memory. Save * errno, free up the current structure and the @@ -1483,7 +1481,7 @@ maxlen = sp->fts_pathlen - len; } - new_len = len + _D_EXACT_NAMLEN (dp); + new_len = len + d_namelen; if (new_len < len) { /* * In the unlikely event that we would end up