mm_size2ndx: using flsl to calculate the ndx
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
This commit is contained in:
parent
b96ced8f4b
commit
f7dec2c250
@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <nuttx/mm/mm.h>
|
#include <nuttx/mm/mm.h>
|
||||||
|
|
||||||
#include "mm_heap/mm.h"
|
#include "mm_heap/mm.h"
|
||||||
@ -42,19 +44,11 @@
|
|||||||
|
|
||||||
int mm_size2ndx(size_t size)
|
int mm_size2ndx(size_t size)
|
||||||
{
|
{
|
||||||
int ndx = 0;
|
|
||||||
|
|
||||||
if (size >= MM_MAX_CHUNK)
|
if (size >= MM_MAX_CHUNK)
|
||||||
{
|
{
|
||||||
return MM_NNODES - 1;
|
return MM_NNODES - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size >>= MM_MIN_SHIFT;
|
size >>= MM_MIN_SHIFT;
|
||||||
while (size > 1)
|
return flsl(size) - 1;
|
||||||
{
|
|
||||||
ndx++;
|
|
||||||
size >>= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ndx;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user