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

39
nnn.c
View file

@ -1564,37 +1564,20 @@ show_stats(char *fpath, char *fname, struct stat *sb)
return 0; return 0;
} }
/*
* Get the order of 2 for this size
* In brief - return the number of trailing zeroes
*/
static int static int
getorder(size_t size) getorder(size_t size)
{ {
switch (size) { static int count, mask;
case 4096:
return 12; for (mask = 1, count = 0; count < 32; mask <<= 1, ++count)
case 512: if ((size & mask) != 0)
return 9; return count;
case 8192:
return 13; return 32;
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 size_t static size_t