Re: [PATCH v3 0/6] Make Emacs search use sexp format
[notmuch-archives.git] / ed / e4addee90e65dc3fa92278562c3e7dd94c6931
1 Return-Path: <bremner@tethera.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 10892431FBD\r
6         for <notmuch@notmuchmail.org>; Thu,  6 Dec 2012 17:27:34 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id RM+diPo7hqcB for <notmuch@notmuchmail.org>;\r
16         Thu,  6 Dec 2012 17:27:33 -0800 (PST)\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
18         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 3E86A429E34\r
21         for <notmuch@notmuchmail.org>; Thu,  6 Dec 2012 17:27:14 -0800 (PST)\r
22 Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net\r
23         ([142.167.90.129] helo=zancas.localnet)\r
24         by tesseract.cs.unb.ca with esmtpsa\r
25         (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
26         (envelope-from <bremner@tethera.net>)\r
27         id 1Tgmif-0003Ny-C6; Thu, 06 Dec 2012 21:27:13 -0400\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1TgmiZ-0004kz-Vb; Thu, 06 Dec 2012 21:27:08 -0400\r
31 From: david@tethera.net\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [Patch v3b 9/9] tag-util: optimization of tag application\r
34 Date: Thu,  6 Dec 2012 21:26:47 -0400\r
35 Message-Id: <1354843607-17980-10-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.10.4\r
37 In-Reply-To: <1354843607-17980-1-git-send-email-david@tethera.net>\r
38 References: <1354843607-17980-1-git-send-email-david@tethera.net>\r
39 X-Spam_bar: -\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Fri, 07 Dec 2012 01:27:34 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 The idea is not to bother with restore operations if they don't change\r
58 the set of tags. This is actually a relatively common case.\r
59 \r
60 In order to avoid fancy datastructures, this method is quadratic in\r
61 the number of tags; at least on my mail database this doesn't seem to\r
62 be a big problem.\r
63 ---\r
64  tag-util.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
65  1 file changed, 66 insertions(+)\r
66 \r
67 diff --git a/tag-util.c b/tag-util.c\r
68 index 932ee7f..3d54e9e 100644\r
69 --- a/tag-util.c\r
70 +++ b/tag-util.c\r
71 @@ -124,6 +124,69 @@ message_error (notmuch_message_t *message,\r
72      fprintf (stderr, "Status: %s\n", notmuch_status_to_string (status));\r
73  }\r
74  \r
75 +static int\r
76 +makes_changes (notmuch_message_t *message,\r
77 +              tag_op_list_t *list,\r
78 +              tag_op_flag_t flags)\r
79 +{\r
80 +\r
81 +    size_t i;\r
82 +\r
83 +    notmuch_tags_t *tags;\r
84 +    notmuch_bool_t changes = FALSE;\r
85 +\r
86 +    /* First, do we delete an existing tag? */\r
87 +    changes = FALSE;\r
88 +    for (tags = notmuch_message_get_tags (message);\r
89 +        ! changes && notmuch_tags_valid (tags);\r
90 +        notmuch_tags_move_to_next (tags)) {\r
91 +       const char *cur_tag = notmuch_tags_get (tags);\r
92 +       int last_op =  (flags & TAG_FLAG_REMOVE_ALL) ? -1 : 0;\r
93 +\r
94 +       /* slight contortions to count down with an unsigned index */\r
95 +       for (i = list->count; i-- > 0; /*nothing*/) {\r
96 +           if (strcmp (cur_tag, list->ops[i].tag) == 0) {\r
97 +               last_op = list->ops[i].remove ? -1 : 1;\r
98 +               break;\r
99 +           }\r
100 +       }\r
101 +\r
102 +       changes = (last_op == -1);\r
103 +    }\r
104 +    notmuch_tags_destroy (tags);\r
105 +\r
106 +    if (changes)\r
107 +       return TRUE;\r
108 +\r
109 +    /* Now check for adding new tags */\r
110 +    for (i = 0; i < list->count; i++) {\r
111 +       notmuch_bool_t exists = FALSE;\r
112 +\r
113 +       if (list->ops[i].remove)\r
114 +           continue;\r
115 +\r
116 +       for (tags = notmuch_message_get_tags (message);\r
117 +            notmuch_tags_valid (tags);\r
118 +            notmuch_tags_move_to_next (tags)) {\r
119 +           const char *cur_tag = notmuch_tags_get (tags);\r
120 +           if (strcmp (cur_tag, list->ops[i].tag) == 0) {\r
121 +               exists = TRUE;\r
122 +               break;\r
123 +           }\r
124 +       }\r
125 +       notmuch_tags_destroy (tags);\r
126 +\r
127 +       /* the following test is conservative,\r
128 +        * in the sense it ignores cases like +foo ... -foo\r
129 +        * but this is OK from a correctness point of view\r
130 +        */\r
131 +       if (! exists)\r
132 +           return TRUE;\r
133 +    }\r
134 +    return FALSE;\r
135 +\r
136 +}\r
137 +\r
138  notmuch_status_t\r
139  tag_op_list_apply (notmuch_message_t *message,\r
140                    tag_op_list_t *list,\r
141 @@ -133,6 +196,9 @@ tag_op_list_apply (notmuch_message_t *message,\r
142      notmuch_status_t status = 0;\r
143      tag_operation_t *tag_ops = list->ops;\r
144  \r
145 +    if (! (flags & TAG_FLAG_PRE_OPTIMIZED) && ! makes_changes (message, list, flags))\r
146 +       return NOTMUCH_STATUS_SUCCESS;\r
147 +\r
148      status = notmuch_message_freeze (message);\r
149      if (status) {\r
150         message_error (message, status, "freezing message");\r
151 -- \r
152 1.7.10.4\r
153 \r