Add function array_splice just like function list_splice
as it can be done faster at low level.
This commit is contained in:
1 parent
2c9169308b
commit
12b15e0037
2 files changed
+35
No files matched your search
@@ -820,5 +820,24 @@
|
||||
return M_HASH_FINAL (hash); \
|
||||
} \
|
||||
, /* no HASH */ ) \
|
||||
\
|
||||
static inline void \
|
||||
M_C(name, _splice)(array_t a1, array_t a2) \
|
||||
{ \
|
||||
ARRAYI_CONTRACT(a1); \
|
||||
ARRAYI_CONTRACT(a2); \
|
||||
size_t newSize = a1->size + a2->size; \
|
||||
if (newSize > a1->alloc) { \
|
||||
type *ptr = M_GET_REALLOC oplist (type, a1->ptr, newSize); \
|
||||
if (M_UNLIKELY (ptr == NULL) ) { \
|
||||
M_MEMORY_FULL(sizeof (type) * newSize); \
|
||||
} \
|
||||
a1->ptr = ptr; \
|
||||
a1->alloc = newSize; \
|
||||
} \
|
||||
memcpy(&a1->ptr[a1->size], &a2->ptr[0], a2->size * sizeof (type)); \
|
||||
a2->size = 0; \
|
||||
a1->size = newSize; \
|
||||
} \
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user