]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: array - two helpers to avoid wasteful array_count
authorPhil Carmody <phil@dovecot.fi>
Mon, 2 Feb 2015 08:24:42 +0000 (10:24 +0200)
committerPhil Carmody <phil@dovecot.fi>
Mon, 2 Feb 2015 08:24:42 +0000 (10:24 +0200)
There's no need to dereference array->element_size and
perform a division when all you care about is the boolean
isempty/nonempty predicate:

$ git grep 'array_count(.*) > 0' | wc -l
77
$ git grep 'array_count(.*) == 0' | wc -l
95

Changing 6 of them has the following impact on the code:

$ size src/lib-imap-client/imapc-connection.o
   text    data     bss     dec     hex filename
  20879       0       4   20883    5193 src/lib-imap-client/imapc-connection.o
$ size src/lib-imap-client/imapc-connection.o
   text    data     bss     dec     hex filename
  20796       0       4   20800    5140 src/lib-imap-client/imapc-connection.o

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib/array.h

index 6efbdc6b04c561ea7e3c3200cfd6bdba2433d313..dda377936a71069d31cfd61b7180f1ac910cf0a5 100644 (file)
@@ -156,6 +156,11 @@ array_count_i(const struct array *array)
 }
 #define array_count(array) \
        array_count_i(&(array)->arr)
+/* No need for the real count if all we're doing is comparing againts 0 */
+#define array_is_empty(array) \
+       ((array)->arr.buffer->used == 0)
+#define array_not_empty(array) \
+       ((array)->arr.buffer->used > 0)
 
 static inline void
 array_append_i(struct array *array, const void *data, unsigned int count)