dovecot: mail_index_keywords_create*() now drops duplicates.
dovecot at dovecot.org
dovecot at dovecot.org
Sun Sep 2 06:09:02 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/0f1a4b7b39a3
changeset: 6352:0f1a4b7b39a3
user: Timo Sirainen <tss at iki.fi>
date: Sun Sep 02 06:08:58 2007 +0300
description:
mail_index_keywords_create*() now drops duplicates.
diffstat:
1 file changed, 28 insertions(+), 13 deletions(-)
src/lib-index/mail-index-transaction.c | 41 +++++++++++++++++++++-----------
diffs (75 lines):
diff -r 1d2b67440878 -r 0f1a4b7b39a3 src/lib-index/mail-index-transaction.c
--- a/src/lib-index/mail-index-transaction.c Sun Sep 02 05:27:03 2007 +0300
+++ b/src/lib-index/mail-index-transaction.c Sun Sep 02 06:08:58 2007 +0300
@@ -1136,7 +1136,7 @@ mail_index_keywords_create(struct mail_i
{
struct mail_index *index = t->view->index;
struct mail_keywords *k;
- unsigned int i, count;
+ unsigned int src, dest, i, count;
count = strarray_length(keywords);
if (count == 0) {
@@ -1149,14 +1149,21 @@ mail_index_keywords_create(struct mail_i
k = i_malloc(sizeof(struct mail_keywords) +
(sizeof(k->idx) * (count-1)));
k->index = index;
- k->count = count;
/* look up the keywords from index. they're never removed from there
so we can permanently store indexes to them. */
- for (i = 0; i < count; i++) {
- mail_index_keyword_lookup_or_create(index, keywords[i],
- &k->idx[i]);
- }
+ for (src = dest = 0; src < count; src++) {
+ mail_index_keyword_lookup_or_create(index, keywords[src],
+ &k->idx[dest]);
+ /* ignore if this is a duplicate */
+ for (i = 0; i < src; i++) {
+ if (k->idx[i] == k->idx[dest])
+ break;
+ }
+ if (i == src)
+ dest++;
+ }
+ k->count = dest;
return k;
}
@@ -1166,9 +1173,10 @@ mail_index_keywords_create_from_indexes(
*keyword_indexes)
{
struct mail_keywords *k;
- unsigned int count;
-
- count = array_count(keyword_indexes);
+ const unsigned int *indexes;
+ unsigned int src, dest, i, count;
+
+ indexes = array_get(keyword_indexes, &count);
if (count == 0) {
k = i_new(struct mail_keywords, 1);
k->index = t->view->index;
@@ -1179,10 +1187,17 @@ mail_index_keywords_create_from_indexes(
k = i_malloc(sizeof(struct mail_keywords) +
(sizeof(k->idx) * (count-1)));
k->index = t->view->index;
- k->count = count;
-
- memcpy(k->idx, array_idx(keyword_indexes, 0),
- count * sizeof(k->idx[0]));
+
+ /* copy but skip duplicates */
+ for (src = dest = 0; src < count; src++) {
+ for (i = 0; i < src; i++) {
+ if (k->idx[i] == indexes[src])
+ break;
+ }
+ if (i == src)
+ k->idx[dest++] = indexes[src];
+ }
+ k->count = dest;
return k;
}
More information about the dovecot-cvs
mailing list