kmalloc: No need to call fls if the size is already power-of-2 aligned
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 10 Oct 2012 12:40:57 +0000 (20:40 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 10 Oct 2012 12:40:57 +0000 (20:40 +0800)
Reduce code complexity

sys/kern/kern_slaballoc.c

index 362092f..9a80068 100644 (file)
@@ -505,16 +505,12 @@ slab_record_source(SLZone *z, const char *file, int line)
 static __inline unsigned long
 powerof2_size(unsigned long size)
 {
-       int i, wt;
+       int i;
 
-       if (size == 0)
-               return 0;
+       if (size == 0 || powerof2(size))
+               return size;
 
        i = flsl(size);
-       wt = (size & ~(1 << (i - 1)));
-       if (!wt)
-               --i;
-
        return (1UL << i);
 }