A fancier func to get order of 2

This commit is contained in:
Arun Prakash Jana 2017-12-20 00:01:32 +05:30
parent cc1891d351
commit d135af33af
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 11 additions and 28 deletions

39
nnn.c
View File

@ -1564,37 +1564,20 @@ show_stats(char *fpath, char *fname, struct stat *sb)
return 0;
}
/*
* Get the order of 2 for this size
* In brief - return the number of trailing zeroes
*/
static int
getorder(size_t size)
{
switch (size) {
case 4096:
return 12;
case 512:
return 9;
case 8192:
return 13;
case 16384:
return 14;
case 32768:
return 15;
case 65536:
return 16;
case 131072:
return 17;
case 262144:
return 18;
case 524288:
return 19;
case 1048576:
return 20;
case 2048:
return 11;
case 1024:
return 10;
default:
return 0;
}
static int count, mask;
for (mask = 1, count = 0; count < 32; mask <<= 1, ++count)
if ((size & mask) != 0)
return count;
return 32;
}
static size_t