dovecot-2.2: lib: extract sort-helpers into separate sort.h file

dovecot at dovecot.org dovecot at dovecot.org
Mon Sep 21 16:54:53 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/1a5a45c80687
changeset: 19172:1a5a45c80687
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Sep 21 19:51:05 2015 +0300
description:
lib: extract sort-helpers into separate sort.h file
The macro definition was nothing to do with strings, and we can put
trivial common-type comparators here. They didn't need to be static
inline, as they can never be inlined anyway, being only used via
function pointers, but that preserves the closest equivalent to
the current code.

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib-imap-client/imapc-msgmap.c             |   6 ------
 src/lib-storage/index/pop3c/pop3c-sync.c       |   6 ------
 src/lib-storage/list/mailbox-list-index-sync.c |   6 ------
 src/lib/sort.h                                 |  24 ++++++++++++++++++++++++
 src/lib/strfuncs.h                             |   8 +++-----
 src/lib/test-timing.c                          |  10 ----------
 src/plugins/fts-squat/squat-uidlist.c          |   5 -----
 7 files changed, 27 insertions(+), 38 deletions(-)

diffs (129 lines):

diff -r 6377910c19e3 -r 1a5a45c80687 src/lib-imap-client/imapc-msgmap.c
--- a/src/lib-imap-client/imapc-msgmap.c	Mon Sep 21 17:03:19 2015 +0300
+++ b/src/lib-imap-client/imapc-msgmap.c	Mon Sep 21 19:51:05 2015 +0300
@@ -47,12 +47,6 @@
 	return *uidp;
 }
 
-static int uint32_cmp(const uint32_t *p1, const uint32_t *p2)
-{
-	return *p1 < *p2 ? -1 :
-		(*p1 > *p2 ? 1 : 0);
-}
-
 bool imapc_msgmap_uid_to_rseq(struct imapc_msgmap *msgmap,
 			      uint32_t uid, uint32_t *rseq_r)
 {
diff -r 6377910c19e3 -r 1a5a45c80687 src/lib-storage/index/pop3c/pop3c-sync.c
--- a/src/lib-storage/index/pop3c/pop3c-sync.c	Mon Sep 21 17:03:19 2015 +0300
+++ b/src/lib-storage/index/pop3c/pop3c-sync.c	Mon Sep 21 19:51:05 2015 +0300
@@ -189,12 +189,6 @@
 		mailbox_recent_flags_set_seqs(&mbox->box, sync_view, seq1, seq2);
 }
 
-static int uint32_cmp(const uint32_t *u1, const uint32_t *u2)
-{
-	return *u1 < *u2 ? -1 :
-		(*u1 > *u2 ? 1 : 0);
-}
-
 int pop3c_sync(struct pop3c_mailbox *mbox)
 {
         struct mail_index_sync_ctx *index_sync_ctx;
diff -r 6377910c19e3 -r 1a5a45c80687 src/lib-storage/list/mailbox-list-index-sync.c
--- a/src/lib-storage/list/mailbox-list-index-sync.c	Mon Sep 21 17:03:19 2015 +0300
+++ b/src/lib-storage/list/mailbox-list-index-sync.c	Mon Sep 21 19:51:05 2015 +0300
@@ -143,12 +143,6 @@
 	}
 }
 
-static int uint32_cmp(const uint32_t *p1, const uint32_t *p2)
-{
-	return *p1 < *p2 ? -1 :
-		(*p1 > *p2 ? 1 : 0);
-}
-
 static void
 mailbox_list_index_sync_names(struct mailbox_list_index_sync_context *ctx)
 {
diff -r 6377910c19e3 -r 1a5a45c80687 src/lib/sort.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/sort.h	Mon Sep 21 19:51:05 2015 +0300
@@ -0,0 +1,24 @@
+#ifndef SORT_H
+#define SORT_H
+
+#define INTEGER_CMP(name, type)					     \
+	static inline int name(const type *i1, const type *i2)	     \
+	{							     \
+		if (*i1 < *i2)					     \
+			return -1;				     \
+		else if (*i1 > *i2)				     \
+			return 1;				     \
+		else						     \
+			return 0;				     \
+	}
+
+INTEGER_CMP(uint64_cmp, uint64_t)
+INTEGER_CMP(uint32_cmp, uint32_t)
+
+#define i_qsort(base, nmemb, size, cmp) \
+	qsort(base, nmemb, size +					\
+	      CALLBACK_TYPECHECK(cmp, int (*)(typeof(const typeof(*base) *), \
+					      typeof(const typeof(*base) *))), \
+	      (int (*)(const void *, const void *))cmp)
+
+#endif
diff -r 6377910c19e3 -r 1a5a45c80687 src/lib/strfuncs.h
--- a/src/lib/strfuncs.h	Mon Sep 21 17:03:19 2015 +0300
+++ b/src/lib/strfuncs.h	Mon Sep 21 19:51:05 2015 +0300
@@ -94,11 +94,9 @@
 const char **p_strarray_dup(pool_t pool, const char *const *arr)
 	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 
-#define i_qsort(base, nmemb, size, cmp) \
-	qsort(base, nmemb, size + \
-		CALLBACK_TYPECHECK(cmp, int (*)(typeof(const typeof(*base) *), \
-						typeof(const typeof(*base) *))), \
-		(int (*)(const void *, const void *))cmp)
+/* FIXME: v2.3 - sort and search APIs belong into their own header, not here */
+#include "sort.h"
+
 #define i_bsearch(key, base, nmemb, size, cmp) \
 	bsearch(key, base, nmemb, size + \
 		CALLBACK_TYPECHECK(cmp, int (*)(typeof(const typeof(*key) *), \
diff -r 6377910c19e3 -r 1a5a45c80687 src/lib/test-timing.c
--- a/src/lib/test-timing.c	Mon Sep 21 17:03:19 2015 +0300
+++ b/src/lib/test-timing.c	Mon Sep 21 19:51:05 2015 +0300
@@ -5,16 +5,6 @@
 
 #include <stdlib.h>
 
-static int uint64_cmp(const uint64_t *i1, const uint64_t *i2)
-{
-	if (*i1 < *i2)
-		return -1;
-	else if (*i1 > *i2)
-		return 1;
-	else
-		return 0;
-}
-
 static void
 test_timing_verify(const struct timing *t, const int64_t *input,
 		   unsigned int input_size)
diff -r 6377910c19e3 -r 1a5a45c80687 src/plugins/fts-squat/squat-uidlist.c
--- a/src/plugins/fts-squat/squat-uidlist.c	Mon Sep 21 17:03:19 2015 +0300
+++ b/src/plugins/fts-squat/squat-uidlist.c	Mon Sep 21 19:51:05 2015 +0300
@@ -1382,11 +1382,6 @@
 	return 0;
 }
 
-static int uint32_cmp(const uint32_t *key, const uint32_t *data)
-{
-	return (int)*key - (int)*data;
-}
-
 static int
 squat_uidlist_get_offset(struct squat_uidlist *uidlist, uint32_t uid_list_idx,
 			 uint32_t *offset_r, uint32_t *num_r)


More information about the dovecot-cvs mailing list