summaryrefslogtreecommitdiffstats
path: root/libglusterfs
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-29 10:42:06 -0700
commitf5ec3b6a9597bb50fe4d8b6a4c9d92a3b46306dc (patch)
tree55bd460a2b6e652fcee6676ce590e47a48061cf4 /libglusterfs
parente3e880180165efffbc0866eeda2154004f7d64f5 (diff)
libglusterfs-fd: Simplify gf_roundup_power_of_two
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfs')
-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 39385fd7577..a5a63ebaadd 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