From 8717f85608d8f7510dc342a7eaee9d159c6e0b00 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Tue, 14 Sep 2021 08:28:03 +0800 Subject: [PATCH] fast_allocator.c: optimize for the region with single allocator --- src/fast_allocator.c | 9 +++++++++ src/tests/test_sorted_array.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fast_allocator.c b/src/fast_allocator.c index 23941eb..51a8f46 100644 --- a/src/fast_allocator.c +++ b/src/fast_allocator.c @@ -167,6 +167,15 @@ static int region_init(struct fast_allocator_context *acontext, return result; } + if (region->count == 1) { + if (region->start == 0) { + region->step += sizeof(struct allocator_wrapper); + } else { + region->start += sizeof(struct allocator_wrapper); + } + region->end += sizeof(struct allocator_wrapper); + } + name = name_buff; result = 0; allocator = region->allocators; diff --git a/src/tests/test_sorted_array.c b/src/tests/test_sorted_array.c index 918f993..577de44 100644 --- a/src/tests/test_sorted_array.c +++ b/src/tests/test_sorted_array.c @@ -26,7 +26,7 @@ #include "fastcommon/array_allocator.h" #include "fastcommon/sorted_array.h" -#define ELEMENT_COUNT 5 * 1000 +#define ELEMENT_COUNT 1000 static bool silence;