1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-08-16 23:08:57 +02:00

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.
This commit is contained in:
Jim Meyering
2010-07-07 11:57:26 +02:00
parent 335b59b962
commit f6e8c18f8d
2 changed files with 12 additions and 8 deletions
+6 -4
View 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;
+6 -4
View 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;