Replace method EXPECTED_SIZE by INC_ALLOC so that all the way of increasing
the size in case of reallocation can be configured and not only the minimum size.
This commit is contained in:
1 parent
95f467f4be
commit
0b44a55b6a
4 files changed
+9
-15
No files matched your search
@@ -2633,7 +2633,7 @@ than an 'uint32_t'.
|
||||
##### M\_GET\_IN\_STR oplist
|
||||
##### M\_GET\_SEPARATOR oplist
|
||||
##### M\_GET\_EXT\_ALGO oplist
|
||||
##### M\_GET\_EXPECTED\_SIZE oplist
|
||||
##### M\_GET\_INC\_ALLOC oplist
|
||||
##### M\_GET\_OOR\_SET oplist
|
||||
##### M\_GET\_OOR\_EQUAL oplist
|
||||
|
||||
|
||||
@@ -90,12 +90,6 @@
|
||||
assert (a->size == 0 || a->ptr != NULL); \
|
||||
} while (0)
|
||||
|
||||
// Compute alloc from the requested size.
|
||||
// NOTE: EXPECTED_SIZE can be overloaded by the given oplist.
|
||||
// TODO: Factor 2 should be configurable. Maybe this macro shall be the operator itself!
|
||||
#define ARRAYI_INC_ALLOC_SIZE(oplist, n) \
|
||||
(M_MAX(M_GET_EXPECTED_SIZE oplist, (n))*2)
|
||||
|
||||
// Deferred evaluation.
|
||||
#define ARRAYI_DEF(arg) ARRAYI_DEF2 arg
|
||||
|
||||
@@ -221,7 +215,7 @@
|
||||
ARRAYI_CONTRACT(v); \
|
||||
if (M_UNLIKELY (v->size >= v->alloc)) { \
|
||||
assert(v->size == v->alloc); \
|
||||
size_t alloc = ARRAYI_INC_ALLOC_SIZE(oplist, v->alloc); \
|
||||
size_t alloc = M_GET_INC_ALLOC oplist (v->alloc); \
|
||||
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||
return NULL; \
|
||||
@@ -268,7 +262,7 @@
|
||||
assert (key <= v->size); \
|
||||
if (M_UNLIKELY (v->size >= v->alloc) ) { \
|
||||
assert(v->size == v->alloc); \
|
||||
size_t alloc = ARRAYI_INC_ALLOC_SIZE(oplist, v->alloc); \
|
||||
size_t alloc = M_GET_INC_ALLOC oplist (v->alloc); \
|
||||
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||
return ; \
|
||||
@@ -350,7 +344,7 @@
|
||||
if (v->size <= size) { \
|
||||
/* Increase size of array */ \
|
||||
if (M_UNLIKELY (size > v->alloc) ) { \
|
||||
size_t alloc = ARRAYI_INC_ALLOC_SIZE(oplist, size) ; \
|
||||
size_t alloc = M_GET_INC_ALLOC oplist (size) ; \
|
||||
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||
return ; \
|
||||
@@ -426,7 +420,7 @@
|
||||
assert(i <= v->size); \
|
||||
size_t size = v->size + num; \
|
||||
if (size > v->alloc) { \
|
||||
size_t alloc = ARRAYI_INC_ALLOC_SIZE(oplist, size) ; \
|
||||
size_t alloc = M_GET_INC_ALLOC oplist (size) ; \
|
||||
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||
return ; \
|
||||
|
||||
@@ -858,7 +858,7 @@ m_core_hash (const void *str, size_t length)
|
||||
#define M_IN_STR_IN_STR(a) ,a,
|
||||
#define M_SEPARATOR_SEPARATOR(a) ,a,
|
||||
#define M_EXT_ALGO_EXT_ALGO(a) ,a,
|
||||
#define M_EXPECTED_SIZE_EXPECTED_SIZE(a) ,a,
|
||||
#define M_INC_ALLOC_INC_ALLOC(a) ,a,
|
||||
#define M_OOR_SET_OOR_SET(a) ,a,
|
||||
#define M_OOR_EQUAL_OOR_EQUAL(a) ,a,
|
||||
|
||||
@@ -920,7 +920,7 @@ m_core_hash (const void *str, size_t length)
|
||||
#define M_GET_IN_STR(...) M_GET_METHOD(IN_STR, M_NO_DEFAULT, __VA_ARGS__)
|
||||
#define M_GET_SEPARATOR(...) M_GET_METHOD(SEPARATOR, ',', __VA_ARGS__)
|
||||
#define M_GET_EXT_ALGO(...) M_GET_METHOD(EXT_ALGO, M_NO_EXT_ALGO, __VA_ARGS__)
|
||||
#define M_GET_EXPECTED_SIZE(...) M_GET_METHOD(EXPECTED_SIZE, 8, __VA_ARGS__)
|
||||
#define M_GET_INC_ALLOC(...) M_GET_METHOD(INC_ALLOC, M_INC_ALLOC_DEFAULT, __VA_ARGS__)
|
||||
#define M_GET_OOR_SET(...) M_GET_METHOD(OOR_SET, M_NO_DEFAULT, __VA_ARGS__)
|
||||
#define M_GET_OOR_EQUAL(...) M_GET_METHOD(OOR_EQUAL, M_NO_DEFAULT, __VA_ARGS__)
|
||||
|
||||
@@ -943,6 +943,7 @@ m_core_hash (const void *str, size_t length)
|
||||
#define M_MUL_DEFAULT(a,b,c) ((a) = (b) * (c))
|
||||
#define M_DIV_DEFAULT(a,b,c) ((a) = (b) / (c))
|
||||
#define M_NO_EXT_ALGO(n,co,to)
|
||||
#define M_INC_ALLOC_DEFAULT(n) (M_MAX(8, (n))*2)
|
||||
|
||||
/* NOTE: Theses operators are NOT compatible with the '[1]' tricks
|
||||
if the variable is defined as a parameter of a function
|
||||
|
||||
Reference in new issue
Block a user