aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-05-24 09:04:38 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-05-24 09:04:38 +0800
commit57bdb1acbf23bb8d99e74ec77a38a66e46e95b6a (patch)
treeee2fde72c7247fc4a143adbedf8cbc9240ec2053 /camel
parenta2f50bb029eaa8b8c0804a5788302dc15105a3ed (diff)
downloadgsoc2013-evolution-57bdb1acbf23bb8d99e74ec77a38a66e46e95b6a.tar
gsoc2013-evolution-57bdb1acbf23bb8d99e74ec77a38a66e46e95b6a.tar.gz
gsoc2013-evolution-57bdb1acbf23bb8d99e74ec77a38a66e46e95b6a.tar.bz2
gsoc2013-evolution-57bdb1acbf23bb8d99e74ec77a38a66e46e95b6a.tar.lz
gsoc2013-evolution-57bdb1acbf23bb8d99e74ec77a38a66e46e95b6a.tar.xz
gsoc2013-evolution-57bdb1acbf23bb8d99e74ec77a38a66e46e95b6a.tar.zst
gsoc2013-evolution-57bdb1acbf23bb8d99e74ec77a38a66e46e95b6a.zip
Optimize the match "" case.
2001-05-23 Jeffrey Stedfast <fejj@ximian.com> * providers/imap/camel-imap-search.c (imap_body_contains): Optimize the match "" case. svn path=/trunk/; revision=9955
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog5
-rw-r--r--camel/providers/imap/camel-imap-search.c47
2 files changed, 35 insertions, 17 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 28e511d4b7..440018d38f 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,8 @@
+2001-05-23 Jeffrey Stedfast <fejj@ximian.com>
+
+ * providers/imap/camel-imap-search.c (imap_body_contains):
+ Optimize the match "" case.
+
2001-05-21 Jeffrey Stedfast <fejj@ximian.com>
* providers/imap/camel-imap-store.c (get_folder_info_online):
diff --git a/camel/providers/imap/camel-imap-search.c b/camel/providers/imap/camel-imap-search.c
index be8ed85eca..3c96449963 100644
--- a/camel/providers/imap/camel-imap-search.c
+++ b/camel/providers/imap/camel-imap-search.c
@@ -73,7 +73,7 @@ imap_body_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv,
{
CamelImapStore *store = CAMEL_IMAP_STORE (s->folder->parent_store);
char *value = argv[0]->value.string;
- CamelImapResponse *response;
+ CamelImapResponse *response = NULL;
char *result, *p, *lasts = NULL, *real_uid;
const char *uid = "";
ESExpResult *r;
@@ -82,25 +82,38 @@ imap_body_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv,
if (s->current) {
uid = camel_message_info_uid (s->current);
- r = e_sexp_result_new(f, ESEXP_RES_BOOL);
+ r = e_sexp_result_new (f, ESEXP_RES_BOOL);
r->value.bool = FALSE;
response = camel_imap_command (store, s->folder, NULL,
"UID SEARCH UID %s BODY \"%s\"",
uid, value);
} else {
- r = e_sexp_result_new(f, ESEXP_RES_ARRAY_PTR);
- r->value.ptrarray = g_ptr_array_new ();
- response = camel_imap_command (store, s->folder, NULL,
- "UID SEARCH BODY \"%s\"",
- value);
+ r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+
+ if (argc == 1 && *value == '\0' && s->folder) {
+ /* optimise the match "" case - match everything */
+ int i;
+
+ r->value.ptrarray = g_ptr_array_new ();
+ for (i = 0; i < s->summary->len; i++) {
+ CamelMessageInfo *info = g_ptr_array_index (s->summary, i);
+ g_ptr_array_add (r->value.ptrarray, (char *)camel_message_info_uid (info));
+ }
+ } else {
+ /* FIXME: danw: what if we have multiple string args? */
+ r->value.ptrarray = g_ptr_array_new ();
+ response = camel_imap_command (store, s->folder, NULL,
+ "UID SEARCH BODY \"%s\"",
+ value);
+ }
}
-
+
if (!response)
return r;
result = camel_imap_response_extract (store, response, "SEARCH", NULL);
if (!result)
return r;
-
+
p = result + sizeof ("* SEARCH");
for (p = strtok_r (p, " ", &lasts); p; p = strtok_r (NULL, " ", &lasts)) {
if (s->current) {
@@ -114,22 +127,22 @@ imap_body_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv,
the search, and wont vanish on us */
if (uid_hash == NULL) {
int i;
-
- uid_hash = g_hash_table_new(g_str_hash, g_str_equal);
- for (i=0;i<s->summary->len;i++) {
+
+ uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ for (i = 0; i < s->summary->len; i++) {
info = s->summary->pdata[i];
- g_hash_table_insert(uid_hash, (char *)camel_message_info_uid(info), info);
+ g_hash_table_insert (uid_hash, (char *)camel_message_info_uid (info), info);
}
}
- if (g_hash_table_lookup_extended(uid_hash, p, (void *)&real_uid, (void *)&info))
+ if (g_hash_table_lookup_extended (uid_hash, p, (void *)&real_uid, (void *)&info))
g_ptr_array_add (r->value.ptrarray, real_uid);
}
}
-
+
/* we could probably cache this globally, but its probably not worth it */
if (uid_hash)
- g_hash_table_destroy(uid_hash);
-
+ g_hash_table_destroy (uid_hash);
+
return r;
}