From: Phil Carmody Date: Mon, 2 Feb 2015 08:24:42 +0000 (+0200) Subject: lib: array - two helpers to avoid wasteful array_count X-Git-Tag: 2.2.16.rc1~95 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fbb70476f061c614bc7a99889e76f988d1cf4019;p=thirdparty%2Fdovecot%2Fcore.git lib: array - two helpers to avoid wasteful array_count 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 --- diff --git a/src/lib/array.h b/src/lib/array.h index 6efbdc6b04..dda377936a 100644 --- a/src/lib/array.h +++ b/src/lib/array.h @@ -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)