From 1d569ca4e7e6147793e6e6510e5a36a4139b2f31 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 26 Sep 2008 13:43:00 +0200 Subject: [PATCH] fts: tweak inode comparison function * lib/fts.c (fts_compare_ino): Sort on increasing, not decreasing inode numbers, as documented. SCALAR(0xeb1b20) --- ChangeLog | 5 +++++ lib/fts.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index db626d3d0..2ee1db36e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2008-09-26 Jim Meyering + fts: tweak inode comparison function + * lib/fts.c (fts_compare_ino): Sort on increasing, not decreasing + inode numbers, as documented. + fts: sort dirent entries on inode number before traversing This avoids a quadratic, seek-related performance penalty when operating on a directory containing many entries (measurable at 10k; @@ -12,6 +16,7 @@ (dirent_inode_sort_may_be_useful, fts_compare_ino): Likewise. (fts_build): Set the stat.st_ino member from D_INO. If it is likely to be useful, sort dirent entries on inode number. + * m4/fts.m4 (gl_FUNC_FTS_CORE): Check for fstatfs, sys/vfs.h, and the struct statfs.f_type member. * modules/fts (Depends-on): Add d-ino. diff --git a/lib/fts.c b/lib/fts.c index 3cf49fa83..673693a67 100644 --- a/lib/fts.c +++ b/lib/fts.c @@ -981,8 +981,8 @@ static bool dirent_inode_sort_may_be_useful (FTS const *sp) { return true; } static int fts_compare_ino (struct _ftsent const **a, struct _ftsent const **b) { - return (a[0]->fts_statp->st_ino < b[0]->fts_statp->st_ino ? 1 - : b[0]->fts_statp->st_ino < a[0]->fts_statp->st_ino ? -1 : 0); + return (a[0]->fts_statp->st_ino < b[0]->fts_statp->st_ino ? -1 + : b[0]->fts_statp->st_ino < a[0]->fts_statp->st_ino ? 1 : 0); } /* -- 2.11.0