pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:418:    else *_v &= ~(BV_ONE << bit);   }      static INLINE int bv_get(struct bitvector * bv, size_t n) {    size_t bit = n % BV_LENGTH;    size_t c = n / BV_LENGTH;    return !!(bv->v[c] & (BV_ONE << bit));   }      static size_t bv_ctz(struct bitvector * bv, size_t n) { -  size_t bit = n % BV_LENGTH; -  size_t c = n / BV_LENGTH; -  bv_int_t * _v = bv->v + c; -  bv_int_t V = *_v & (~BV_NIL << bit); +  size_t bit; +  size_t c; +  bv_int_t * _v; +  bv_int_t V;    -  +  if (n < bv->length) { +  bit = n % BV_LENGTH; +  c = n / BV_LENGTH; +  _v = bv->v + c; +  V = *_v & (~BV_NIL << bit); +     bit = c * BV_LENGTH;       while (1) { -  if (V) return bit + BV_CTZ(V); +  if (V) { +  bit += BV_CTZ(V); +  if (bit >= bv->length) break; +  return bit; +  }       bit += BV_LENGTH;       if (bit >= bv->length) break;       V = *(++_v);    } -  +  }       return (size_t)-1;   }      #ifdef PIKE_DEBUG   static void ATTRIBUTE((unused)) bv_print(struct bitvector * bv) {    size_t i;    for (i = 0; i < bv->length; i++) {    fprintf(stderr, "%d", bv_get(bv, i));    }