+/* Licensed under LGPLv2.1+ - see LICENSE file for details */
#include "tiny.h"
#include "bitops.h"
#include <assert.h>
/* Val is usually offset by MIN_BLOCK_SIZE here. */
static unsigned encode_length(unsigned long val)
{
- unsigned int bits = fls(val);
+ unsigned int bits = afls(val);
/* 5 bits in first byte. */
if (bits <= 5)
return 1;
/* Walk through and try to coalesce */
static bool try_coalesce(unsigned char *pool, unsigned long poolsize)
{
- unsigned long len, hdrlen, prev_off = 0, prev_len = 0, off;
+ unsigned long len, prev_off = 0, prev_len = 0, off;
bool free, prev_free = false, coalesced = false;
off = free_array_size(poolsize);
do {
- hdrlen = decode(&len, &free, pool + off);
+ decode(&len, &free, pool + off);
if (free && prev_free) {
prev_len += len;
encode(prev_len, true, pool + prev_off);
unsigned long size, unsigned long align)
{
unsigned long arrsize = free_array_size(poolsize);
- unsigned long len, off, actual, hdr, hdrlen, free_bucket;
+ unsigned long len, off, actual, hdr, free_bucket;
long fa_off;
unsigned char *arr = pool;
bool free, coalesced = false;
if (!off)
continue;
- hdrlen = decode(&len, &free, arr + off);
+ decode(&len, &free, arr + off);
if (long_enough(off, len, size, align)) {
/* Remove it. */
memset(&arr[fa_off], 0, 3);
again:
off = arrsize;
- hdrlen = decode(&len, &free, arr + off);
+ decode(&len, &free, arr + off);
while (!free || !long_enough(off, len, size, align)) {
/* Refill free array as we go. */
if (free && coalesced)
}
return NULL;
}
- hdrlen = decode(&len, &free, arr + off);
+ decode(&len, &free, arr + off);
}
found: