dovecot-2.2: lib: array - two helpers to avoid wasteful array_count

dovecot at dovecot.org dovecot at dovecot.org
Mon Feb 2 08:27:00 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/b0ac11ef7f51
changeset: 18211:b0ac11ef7f51
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Feb 02 10:24:42 2015 +0200
description:
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 <phil at dovecot.fi>

diffstat:

 src/lib/array.h |  5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diffs (15 lines):

diff -r ad04a5e6a766 -r b0ac11ef7f51 src/lib/array.h
--- a/src/lib/array.h	Sat Jan 31 01:10:56 2015 +0200
+++ b/src/lib/array.h	Mon Feb 02 10:24:42 2015 +0200
@@ -156,6 +156,11 @@
 }
 #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)


More information about the dovecot-cvs mailing list