[tor-commits] [tor/master] Make preferred_chunk_size nonstatic, and add a prefix to it
nickm at torproject.org
nickm at torproject.org
Tue Sep 5 18:18:13 UTC 2017
commit c0b9f594b65f410cf219673d53226ed4eeeedc19
Author: Nick Mathewson <nickm at torproject.org>
Date: Tue Sep 5 14:15:38 2017 -0400
Make preferred_chunk_size nonstatic, and add a prefix to it
---
src/common/buffers.c | 10 +++++-----
src/common/buffers.h | 2 +-
src/test/test_buffers.c | 18 +++++++++---------
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/common/buffers.c b/src/common/buffers.c
index f9118dd2f..50673646d 100644
--- a/src/common/buffers.c
+++ b/src/common/buffers.c
@@ -173,8 +173,8 @@ chunk_grow(chunk_t *chunk, size_t sz)
/** 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)
@@ -228,7 +228,7 @@ buf_pullup(buf_t *buf, size_t bytes, const char **head_out, size_t *len_out)
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) {
@@ -344,7 +344,7 @@ buf_t *
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;
}
@@ -469,7 +469,7 @@ buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
} 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();
diff --git a/src/common/buffers.h b/src/common/buffers.h
index 0db4f771d..5a52b2a81 100644
--- a/src/common/buffers.h
+++ b/src/common/buffers.h
@@ -67,7 +67,7 @@ void buf_pullup(buf_t *buf, size_t bytes,
#ifdef TOR_UNIT_TESTS
buf_t *buf_new_with_data(const char *cp, size_t sz);
#endif
-ATTR_UNUSED STATIC size_t preferred_chunk_size(size_t target);
+size_t buf_preferred_chunk_size(size_t target);
#define DEBUG_CHUNK_ALLOC
/** A single chunk on a buffer. */
diff --git a/src/test/test_buffers.c b/src/test/test_buffers.c
index 1fd2cd71d..dfc1fcb24 100644
--- a/src/test/test_buffers.c
+++ b/src/test/test_buffers.c
@@ -783,17 +783,17 @@ test_buffers_chunk_size(void *arg)
(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:
;
}
More information about the tor-commits
mailing list