dovecot-2.2: lib-dict: Added DICT_ITERATE_FLAG_NO_VALUE

dovecot at dovecot.org dovecot at dovecot.org
Sat Oct 13 04:28:25 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/e7f10acf65e3
changeset: 15222:e7f10acf65e3
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Oct 13 04:17:45 2012 +0300
description:
lib-dict: Added DICT_ITERATE_FLAG_NO_VALUE
This allows iterating dictionary without wasting extra time on returning
values that aren't needed.

diffstat:

 src/lib-dict/dict-sql.c |  9 +++++++--
 src/lib-dict/dict.h     |  3 ++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diffs (39 lines):

diff -r 327dc9a8decc -r e7f10acf65e3 src/lib-dict/dict-sql.c
--- a/src/lib-dict/dict-sql.c	Sat Oct 13 01:57:24 2012 +0300
+++ b/src/lib-dict/dict-sql.c	Sat Oct 13 04:17:45 2012 +0300
@@ -356,7 +356,10 @@
 	T_BEGIN {
 		string_t *query = t_str_new(256);
 
-		str_printfa(query, "SELECT %s", map->value_field);
+		str_append(query, "SELECT ");
+		if ((ctx->flags & DICT_ITERATE_FLAG_NO_VALUE) == 0)
+			str_printfa(query, "%s,", map->value_field);
+
 		/* get all missing fields */
 		sql_fields = array_get(&map->sql_fields, &count);
 		i = array_count(&values);
@@ -367,7 +370,9 @@
 			i--;
 		}
 		for (; i < count; i++)
-			str_printfa(query, ",%s", sql_fields[i]);
+			str_printfa(query, "%s,", sql_fields[i]);
+		str_truncate(query, str_len(query)-1);
+
 		str_printfa(query, " FROM %s", map->table);
 
 		recurse_type = (ctx->flags & DICT_ITERATE_FLAG_RECURSE) == 0 ?
diff -r 327dc9a8decc -r e7f10acf65e3 src/lib-dict/dict.h
--- a/src/lib-dict/dict.h	Sat Oct 13 01:57:24 2012 +0300
+++ b/src/lib-dict/dict.h	Sat Oct 13 04:17:45 2012 +0300
@@ -9,7 +9,8 @@
 enum dict_iterate_flags {
 	DICT_ITERATE_FLAG_RECURSE             = 0x01,
 	DICT_ITERATE_FLAG_SORT_BY_KEY         = 0x02,
-	DICT_ITERATE_FLAG_SORT_BY_VALUE       = 0x04
+	DICT_ITERATE_FLAG_SORT_BY_VALUE       = 0x04,
+	DICT_ITERATE_FLAG_NO_VALUE            = 0x08
 };
 
 enum dict_data_type {


More information about the dovecot-cvs mailing list