summaryrefslogtreecommitdiff
path: root/magic_buddy
diff options
context:
space:
mode:
Diffstat (limited to 'magic_buddy')
-rw-r--r--magic_buddy/magic_buddy.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/magic_buddy/magic_buddy.c b/magic_buddy/magic_buddy.c
index 9d3e1e9..1eb2d8f 100644
--- a/magic_buddy/magic_buddy.c
+++ b/magic_buddy/magic_buddy.c
@@ -12,13 +12,10 @@ struct free_block {
// log2 of size rounded up (ceil) or down (!ceil) to the nearest power of 2
static size_t size2log(size_t size, int ceil) {
- size_t bitcnt = 0, floor_log = 0;
- for (int i = 0; i < (8 * sizeof(size)); i++, size >>= 1) {
- if (!(size & 1)) continue;
- bitcnt++;
- floor_log = i;
- }
- return (ceil && (bitcnt > 1)) ? (floor_log + 1) : floor_log;
+ size_t floor_log = 0;
+ for (size_t i = 0; i < (8 * sizeof(size)); i++)
+ if (size & (1 << i)) floor_log = i;
+ return (ceil && (size > (1 << floor_log))) ? (floor_log + 1) : floor_log;
}
static struct free_block *buddy_of(struct free_block *block, size_t logsize,
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback