]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
di-set, ino-map: adjust a type, improve readability
authorJim Meyering <meyering@redhat.com>
Wed, 7 Jul 2010 09:57:26 +0000 (11:57 +0200)
committerJim Meyering <meyering@redhat.com>
Tue, 13 Jul 2010 00:20:10 +0000 (02:20 +0200)
* 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.

gl/lib/di-set.c
gl/lib/ino-map.c

index ba44bcfff3d148cbf6aa33b349f70e746abc31a4..892950dbb52ce4ef864195d3091d8b4d8cd843db 100644 (file)
@@ -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;
index cc9a131c98a29d1e05157b3a3796a1c91f829119..f6fdd6395f95bb8be0707de0529a43c39275e5aa 100644 (file)
@@ -56,11 +56,13 @@ ino_hash (void const *x, size_t table_size)
   struct ino_map_ent const *p = x;
   ino_t ino = p->ino;
 
-  /* Exclusive-OR the words of INO into H.  This avoids loss of info,
-     without using a wider % that could be quite slow.  */
+  /* When INO is wider than size_t, exclusive-OR the words of INO into H.
+     This avoids loss of info, without applying % to the wider type,
+     which could be quite slow on some systems.  */
   size_t h = ino;
-  int i;
-  for (i = 1; i < sizeof ino / sizeof h + (sizeof ino % sizeof h != 0); i++)
+  unsigned int i;
+  unsigned int n_words = sizeof ino / sizeof h + (sizeof ino % sizeof h != 0);
+  for (i = 1; i < n_words; i++)
     h ^= ino >> CHAR_BIT * sizeof h * i;
 
   return h % table_size;