]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Remove array_swap()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 10 Feb 2021 20:06:29 +0000 (22:06 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 7 May 2021 10:09:35 +0000 (10:09 +0000)
It's not used anywhere, and it's a bit too weird.

src/lib/array.h
src/lib/test-array.c

index a1680203b97178ae53d9f16b493a6de56bcf34a6..e4e5cede2b3944ace54b0392c09a3eb36fe41b1a 100644 (file)
@@ -317,25 +317,6 @@ array_copy(struct array *dest, unsigned int dest_idx,
                    count * dest->element_size);
 }
 
-/* Exchange ownership of two arrays, which should have been allocated
-   from the same pool/context. Useful for updating an array with a
-   replacement. Can also do it with uninitialized arrays (which will
-   have .element_size == 0). */
-static inline void
-array_swap_i(struct array *array1, struct array *array2)
-{
-       buffer_t *buffer = array1->buffer;
-       size_t elsize = array1->element_size;
-
-       array1->buffer = array2->buffer;
-       array1->element_size = array2->element_size;
-       array2->buffer = buffer;
-       array2->element_size = elsize;
-}
-#define array_swap(array1, array2) \
-       TYPE_CHECKS(void, ARRAY_TYPES_CHECK(array1, array2), \
-       array_swap_i(&(array1)->arr, &(array2)->arr))
-
 bool array_cmp_i(const struct array *array1,
                 const struct array *array2) ATTR_PURE;
 #define array_cmp(array1, array2) \
index 5309464f04e074ba016e61ae29892007c73ed932..36a64ba81698d147d6cd4b970f9b4d69f19e4318 100644 (file)
@@ -80,28 +80,6 @@ static void test_array_foreach_elem_string(void)
        test_end();
 }
 
-static void test_array_swap(void)
-{
-       ARRAY(struct foo) foos[3];
-       struct foo nfoo;
-       int i, j;
-
-       test_begin("array swap");
-       for (i = 1; i <= 3; i++) {
-               t_array_init(&foos[i-1], i);
-               for (j = 1; j <= 2*i+1; j++) {
-                       nfoo.a = nfoo.b = nfoo.c = j;
-                       array_push_back(&foos[i - 1], &nfoo);
-               }
-       }
-       for (i = 0; i < 1000; i++)
-               array_swap(&foos[i_rand_limit(3)], &foos[i_rand_limit(3)]);
-       /* Just want size 3, 5, and 7 in any order */
-       test_assert(array_count(&foos[0]) * array_count(&foos[1]) * array_count(&foos[2]) == 3*5*7);
-       test_assert(array_count(&foos[0]) + array_count(&foos[1]) + array_count(&foos[2]) == 3+5+7);
-       test_end();
-}
-
 static int test_int_compare(const int *key, const int *elem)
 {
        return (*key < *elem) ? -1 :
@@ -292,7 +270,6 @@ void test_array(void)
        test_array_reverse();
        test_array_cmp();
        test_array_cmp_str();
-       test_array_swap();
        test_array_free();
 }