From 4b66297ea0b0ed2ec5c4421878a31f5b27448624 Mon Sep 17 00:00:00 2001 From: Yinan Zhang Date: Thu, 2 Apr 2020 13:14:24 -0700 Subject: [PATCH] Add move constructor to ql module --- include/jemalloc/internal/ql.h | 5 +++++ test/unit/ql.c | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/jemalloc/internal/ql.h b/include/jemalloc/internal/ql.h index b1ce4793..16cd88d5 100644 --- a/include/jemalloc/internal/ql.h +++ b/include/jemalloc/internal/ql.h @@ -18,6 +18,11 @@ struct { \ (a_head)->qlh_first = NULL; \ } while (0) +#define ql_move(a_head_dest, a_head_src) do { \ + (a_head_dest)->qlh_first = (a_head_src)->qlh_first; \ + (a_head_src)->qlh_first = NULL; \ +} while (0) + #define ql_empty(a_head) ((a_head)->qlh_first == NULL) #define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field) diff --git a/test/unit/ql.c b/test/unit/ql.c index 8f689389..f9130582 100644 --- a/test/unit/ql.c +++ b/test/unit/ql.c @@ -282,6 +282,26 @@ TEST_BEGIN(test_ql_rotate) { } TEST_END +TEST_BEGIN(test_ql_move) { + list_head_t head_dest, head_src; + list_t entries[NENTRIES]; + unsigned i; + + ql_new(&head_src); + ql_move(&head_dest, &head_src); + test_empty_list(&head_src); + test_empty_list(&head_dest); + + init_entries(entries, sizeof(entries)/sizeof(list_t)); + for (i = 0; i < NENTRIES; i++) { + ql_tail_insert(&head_src, &entries[i], link); + } + ql_move(&head_dest, &head_src); + test_empty_list(&head_src); + test_entries_list(&head_dest, entries, NENTRIES); +} +TEST_END + int main(void) { return test( @@ -292,5 +312,6 @@ main(void) { test_ql_head_remove, test_ql_insert, test_ql_concat_split, - test_ql_rotate); + test_ql_rotate, + test_ql_move); }