/** Return the allocation size we'd like to use to hold <b>target</b>
* bytes. */
-STATIC size_t
-preferred_chunk_size(size_t target)
+size_t
+buf_preferred_chunk_size(size_t target)
{
tor_assert(target <= SIZE_T_CEILING - CHUNK_OVERHEAD);
if (CHUNK_ALLOC_SIZE(target) >= MAX_CHUNK_ALLOC)
size_t newsize;
/* We need to grow the chunk. */
chunk_repack(buf->head);
- newsize = CHUNK_SIZE_WITH_ALLOC(preferred_chunk_size(capacity));
+ newsize = CHUNK_SIZE_WITH_ALLOC(buf_preferred_chunk_size(capacity));
newhead = chunk_grow(buf->head, newsize);
tor_assert(newhead->memlen >= capacity);
if (newhead != buf->head) {
buf_new_with_capacity(size_t size)
{
buf_t *b = buf_new();
- b->default_chunk_size = preferred_chunk_size(size);
+ b->default_chunk_size = buf_preferred_chunk_size(size);
return b;
}
} else if (capped && CHUNK_ALLOC_SIZE(capacity) > MAX_CHUNK_ALLOC) {
chunk = chunk_new_with_alloc_size(MAX_CHUNK_ALLOC);
} else {
- chunk = chunk_new_with_alloc_size(preferred_chunk_size(capacity));
+ chunk = chunk_new_with_alloc_size(buf_preferred_chunk_size(capacity));
}
chunk->inserted_time = (uint32_t)monotime_coarse_absolute_msec();
(void)arg;
const int min = 256;
const int max = 65536;
- tt_uint_op(preferred_chunk_size(3), OP_EQ, min);
- tt_uint_op(preferred_chunk_size(25), OP_EQ, min);
- tt_uint_op(preferred_chunk_size(0), OP_EQ, min);
- tt_uint_op(preferred_chunk_size(256), OP_EQ, 512);
- tt_uint_op(preferred_chunk_size(65400), OP_EQ, max);
+ tt_uint_op(buf_preferred_chunk_size(3), OP_EQ, min);
+ tt_uint_op(buf_preferred_chunk_size(25), OP_EQ, min);
+ tt_uint_op(buf_preferred_chunk_size(0), OP_EQ, min);
+ tt_uint_op(buf_preferred_chunk_size(256), OP_EQ, 512);
+ tt_uint_op(buf_preferred_chunk_size(65400), OP_EQ, max);
/* Here, we're implicitly saying that the chunk header overhead is
* between 1 and 100 bytes. 24..48 would probably be more accurate. */
- tt_uint_op(preferred_chunk_size(65536), OP_GT, 65536);
- tt_uint_op(preferred_chunk_size(65536), OP_LT, 65536+100);
- tt_uint_op(preferred_chunk_size(165536), OP_GT, 165536);
- tt_uint_op(preferred_chunk_size(165536), OP_LT, 165536+100);
+ tt_uint_op(buf_preferred_chunk_size(65536), OP_GT, 65536);
+ tt_uint_op(buf_preferred_chunk_size(65536), OP_LT, 65536+100);
+ tt_uint_op(buf_preferred_chunk_size(165536), OP_GT, 165536);
+ tt_uint_op(buf_preferred_chunk_size(165536), OP_LT, 165536+100);
done:
;
}