Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6352:0f1a4b7b39a3 HEAD
mail_index_keywords_create*() now drops duplicates.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 02 Sep 2007 06:08:58 +0300 |
parents | 1d2b67440878 |
children | 23c9ac999578 |
files | src/lib-index/mail-index-transaction.c |
diffstat | 1 files changed, 25 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ { 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 @@ 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 @@ *keyword_indexes) { struct mail_keywords *k; - unsigned int count; + const unsigned int *indexes; + unsigned int src, dest, i, count; - count = array_count(keyword_indexes); + 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 @@ 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; }