summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2009-06-25 14:31:29 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-06-30 14:36:29 -0700
commitdaa5e0e570b89050b0e70256fa239d4e2adc869b (patch)
tree5e54d0c29504cb7f5814b04c72cc4dcacf538c1b
parentd93b62a943f8181928f13175a273bcd9f1e0118f (diff)
libglusterfs-fd: Simplify gf_roundup_power_of_two
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
-rw-r--r--libglusterfs/src/fd.c40
1 files changed, 10 insertions, 30 deletions
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c
index 39385fd75..a5a63ebaa 100644
--- a/libglusterfs/src/fd.c
+++ b/libglusterfs/src/fd.c
@@ -42,39 +42,19 @@ _fd_ref (fd_t *fd);
static inline uint32_t
gf_roundup_power_of_two (uint32_t nr)
{
- uint32_t result = nr;
+ uint32_t result = 1;
- if (nr < 0) {
- gf_log ("server-protocol/fd",
- GF_LOG_ERROR,
- "Negative number passed");
- return -1;
- }
-
- switch (nr) {
- case 0:
- case 1:
- result = 1;
- break;
-
- default:
- {
- uint32_t cnt = 0, tmp = nr;
- uint8_t remainder = 0;
- while (tmp != 1){
- if (tmp % 2)
- remainder = 1;
- tmp /= 2;
- cnt++;
- }
+ if (nr < 0) {
+ gf_log ("server-protocol/fd",
+ GF_LOG_ERROR,
+ "Negative number passed");
+ return -1;
+ }
- if (remainder)
- result = 0x1 << (cnt + 1);
- break;
- }
- }
+ while (result <= nr)
+ result *= 2;
- return result;
+ return result;
}
static int