Add methods push_move & pop_move.
Rewrite _pop_back to be a little bit faster for complex structure as it used DO_MOVE instead of plain _set.
This commit is contained in:
1 parent
281f567d97
commit
86083e3a92
2 files changed
+38
-4
No files matched your search
@@ -76,7 +76,9 @@
|
||||
IT_REMOVE(M_C(name,_remove)), \
|
||||
CLEAN(M_C(name,_clean)), \
|
||||
PUSH(M_C(name,_push_back)), \
|
||||
POP(M_C(name,_pop_back)) \
|
||||
POP(M_C(name,_pop_back)), \
|
||||
PUSH_MOVE(M_C(name,_push_move)), \
|
||||
POP_MOVE(M_C(name,_pop_move)) \
|
||||
,REVERSE(M_C(name,_reverse)) \
|
||||
,OPLIST(oplist) \
|
||||
,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \
|
||||
@@ -217,9 +219,32 @@
|
||||
LISTI_CONTRACT(v); \
|
||||
assert(*v != NULL); \
|
||||
if (data != NULL) { \
|
||||
M_GET_SET oplist(*data, (*v)->data); \
|
||||
M_DO_MOVE (oplist, *data, (*v)->data); \
|
||||
} else { \
|
||||
M_GET_CLEAR oplist((*v)->data); \
|
||||
} \
|
||||
M_GET_CLEAR oplist((*v)->data); \
|
||||
struct M_C(name, _s) *tofree = *v; \
|
||||
*v = (*v)->next; \
|
||||
M_C(name,_int_del)(tofree); \
|
||||
LISTI_CONTRACT(v); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
M_C(name, _push_move)(list_t v, type *x) \
|
||||
{ \
|
||||
assert (x != NULL); \
|
||||
type *data = M_C(name, _push_raw)(v); \
|
||||
if (M_UNLIKELY (data == NULL)) \
|
||||
return; \
|
||||
M_DO_INIT_MOVE (oplist, *data, *x); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
M_C(name, _pop_move)(type *data, list_t v) \
|
||||
{ \
|
||||
LISTI_CONTRACT(v); \
|
||||
assert(*v != NULL && data != NULL); \
|
||||
M_DO_INIT_MOVE (oplist, *data, (*v)->data); \
|
||||
struct M_C(name, _s) *tofree = *v; \
|
||||
*v = (*v)->next; \
|
||||
M_C(name,_int_del)(tofree); \
|
||||
|
||||
+10
-1
@@ -180,7 +180,16 @@ static void test_uint(void)
|
||||
assert (!list_uint_equal_p(v,v2));
|
||||
|
||||
assert (list_uint_hash(v) != 0);
|
||||
|
||||
|
||||
x = 1478963;
|
||||
s = *list_uint_back(v);
|
||||
list_uint_push_move(v, &x);
|
||||
assert (*list_uint_back(v) == 1478963);
|
||||
x = 0;
|
||||
list_uint_pop_move(&x, v);
|
||||
assert (x == 1478963);
|
||||
assert (s == *list_uint_back(v));
|
||||
|
||||
list_uint_clear(v);
|
||||
list_uint_clear(v2);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user