summaryrefslogtreecommitdiff
path: root/gl/lib/di-set.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2010-07-07 11:57:26 +0200
committerJim Meyering <meyering@redhat.com>2010-07-13 02:20:10 +0200
commitf6e8c18f8d2077ea84aef679852622c8bd73789c (patch)
tree30a1dae42ef372d0e0a67cb297babb2432c1f81d /gl/lib/di-set.c
parent335b59b9625758f92ba82cd6b7138f7423df60ef (diff)
downloadcoreutils-f6e8c18f8d2077ea84aef679852622c8bd73789c.tar.xz
di-set, ino-map: adjust a type, improve readability
* gl/lib/ino-map.c (ino_hash): Declare "i" as unsigned int. Use an intermediate variable for the for-loop upper bound, so it's a little more readable. Adjust comment. * gl/lib/di-set.c (di_ent_hash): Likewise.
Diffstat (limited to 'gl/lib/di-set.c')
-rw-r--r--gl/lib/di-set.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/gl/lib/di-set.c b/gl/lib/di-set.c
index ba44bcfff..892950dbb 100644
--- a/gl/lib/di-set.c
+++ b/gl/lib/di-set.c
@@ -78,11 +78,13 @@ di_ent_hash (void const *x, size_t table_size)
struct di_ent const *p = x;
dev_t dev = p->dev;
- /* Exclusive-OR the words of DEV into H. This avoids loss of info,
- without using a wider % that could be quite slow. */
+ /* When DEV is wider than size_t, exclusive-OR the words of DEV into H.
+ This avoids loss of info, without applying % to the wider type,
+ which could be quite slow on some systems. */
size_t h = dev;
- int i;
- for (i = 1; i < sizeof dev / sizeof h + (sizeof dev % sizeof h != 0); i++)
+ unsigned int i;
+ unsigned int n_words = sizeof dev / sizeof h + (sizeof dev % sizeof h != 0);
+ for (i = 1; i < n_words; i++)
h ^= dev >> CHAR_BIT * sizeof h * i;
return h % table_size;