summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5I.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/H5I.c b/src/H5I.c
index a092b24..e8cebb6 100644
--- a/src/H5I.c
+++ b/src/H5I.c
@@ -87,7 +87,8 @@ static herr_t H5I_init_interface(void);
* Map an ID to a hash location (assumes s is a power of 2 and smaller
* than the ID_MASK constant).
*/
-# define H5I_LOC(a,s) ((hid_t)((size_t)(a)&((s)-1)))
+# define H5I_LOC(a,s) ((hid_t)((size_t)(a)&((s)-1)))
+# define POWER_OF_TWO(n) ((((n) - 1) & (n)) == 0 && (n) > 1)
#else
/*
* Map an ID to a hash location.
@@ -219,6 +220,10 @@ H5I_term_interface(void)
* Friday, February 19, 1999
*
* Modifications:
+ * Bill Wendling, 2000-05-05
+ * Instead of the ugly test of whether hash_size is a power of
+ * two, I placed it in a macro POWER_OF_TWO which uses the fact
+ * that a number that is a power of two has only 1 bit set.
*
*-------------------------------------------------------------------------
*/
@@ -236,21 +241,7 @@ H5I_init_group(H5I_type_t grp, size_t hash_size, uintn reserved,
HGOTO_DONE(FAIL);
}
#ifdef HASH_SIZE_POWER_2
- /*
- * If anyone knows a faster test for a power of two, please change this
- * silly code -QAK
- */
- if (!(hash_size == 2 || hash_size == 4 || hash_size == 8 ||
- hash_size == 16 || hash_size == 32 || hash_size == 64 ||
- hash_size == 128 || hash_size == 256 || hash_size == 512 ||
- hash_size == 1024 || hash_size == 2048 || hash_size == 4096 ||
- hash_size == 8192 || hash_size == 16374 || hash_size == 32768 ||
- hash_size == 65536 || hash_size == 131072 || hash_size == 262144 ||
- hash_size == 524288 || hash_size == 1048576 ||
- hash_size == 2097152 || hash_size == 4194304 ||
- hash_size == 8388608 || hash_size == 16777216 ||
- hash_size == 33554432 || hash_size == 67108864 ||
- hash_size == 134217728 || hash_size == 268435456))
+ if (!POWER_OF_TWO(hash_size))
HGOTO_DONE(FAIL);
#endif /* HASH_SIZE_POWER_2 */