[PATCH] bitmap:improve memory usage using CHAR_BITS and unsigned CHAR
[notmuch-archives.git] / a5 / 50d75a0d49e662546f4ebe245d51eff86ac48b
1 Return-Path: <jrollins@finestructure.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 2EF00431FD2\r
6         for <notmuch@notmuchmail.org>; Wed, 16 May 2012 14:56:35 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] 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 bD5+-yg4zxJg for <notmuch@notmuchmail.org>;\r
16         Wed, 16 May 2012 14:56:33 -0700 (PDT)\r
17 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
18         [131.215.239.19])\r
19         by olra.theworths.org (Postfix) with ESMTP id B4E7B431FBD\r
20         for <notmuch@notmuchmail.org>; Wed, 16 May 2012 14:56:15 -0700 (PDT)\r
21 Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
22         by fire-doxen-postvirus (Postfix) with ESMTP id 7EFDB328056\r
23         for <notmuch@notmuchmail.org>; Wed, 16 May 2012 14:56:15 -0700 (PDT)\r
24 X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new\r
25 Received: from finestructure.net (rrcs-184-74-199-219.nyc.biz.rr.com\r
26         [184.74.199.219]) (Authenticated sender: jrollins)\r
27         by fire-doxen-submit (Postfix) with ESMTP id C553F2E50AE0\r
28         for <notmuch@notmuchmail.org>; Wed, 16 May 2012 14:56:12 -0700 (PDT)\r
29 Received: by finestructure.net (Postfix, from userid 1000)\r
30         id 23A8461B; Wed, 16 May 2012 14:56:02 -0700 (PDT)\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>\r
32 To: Notmuch Mail <notmuch@notmuchmail.org>\r
33 Subject: [PATCH 6/6] cli: lazily create the crypto gpg context only when\r
34  needed\r
35 Date: Wed, 16 May 2012 14:55:59 -0700\r
36 Message-Id: <1337205359-2444-7-git-send-email-jrollins@finestructure.net>\r
37 X-Mailer: git-send-email 1.7.10\r
38 In-Reply-To: <1337205359-2444-6-git-send-email-jrollins@finestructure.net>\r
39 References: <1337205359-2444-1-git-send-email-jrollins@finestructure.net>\r
40         <1337205359-2444-2-git-send-email-jrollins@finestructure.net>\r
41         <1337205359-2444-3-git-send-email-jrollins@finestructure.net>\r
42         <1337205359-2444-4-git-send-email-jrollins@finestructure.net>\r
43         <1337205359-2444-5-git-send-email-jrollins@finestructure.net>\r
44         <1337205359-2444-6-git-send-email-jrollins@finestructure.net>\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Wed, 16 May 2012 21:56:35 -0000\r
58 \r
59 Move the creation of the crypto ctx into mime-node.c and create it\r
60 only when needed.  This removes code duplication from notmuch-show and\r
61 notmuch-reply, and should speed up these functions considerably if the\r
62 crypto flags are provided but the messages don't have any\r
63 cryptographic parts.\r
64 ---\r
65  mime-node.c     |   25 +++++++++++++++++++++++++\r
66  notmuch-reply.c |   19 -------------------\r
67  notmuch-show.c  |   23 -----------------------\r
68  3 files changed, 25 insertions(+), 42 deletions(-)\r
69 \r
70 diff --git a/mime-node.c b/mime-node.c\r
71 index 8cdabc8..7278c74 100644\r
72 --- a/mime-node.c\r
73 +++ b/mime-node.c\r
74 @@ -182,6 +182,31 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)\r
75         return NULL;\r
76      }\r
77  \r
78 +    /* Lazily create the gpgctx if it's needed and hasn't been initialized yet */\r
79 +    if ((GMIME_IS_MULTIPART_ENCRYPTED (part) || GMIME_IS_MULTIPART_SIGNED (part))\r
80 +       && (node->ctx->crypto.verify || node->ctx->crypto.decrypt)) {\r
81 +       if (!node->ctx->crypto.gpgctx) {\r
82 +#ifdef GMIME_ATLEAST_26\r
83 +           /* TODO: GMimePasswordRequestFunc */\r
84 +           node->ctx->crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
85 +#else\r
86 +           GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
87 +           node->ctx->crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
88 +           g_object_unref (session);\r
89 +#endif\r
90 +           if (node->ctx->crypto.gpgctx) {\r
91 +               g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) node->ctx->crypto.gpgctx, FALSE);\r
92 +           } else {\r
93 +               /* If we fail to create the gpgctx set the verify and\r
94 +                * decrypt flags to FALSE so we don't try to do any\r
95 +                * further verification or decryption */\r
96 +               node->ctx->crypto.verify = FALSE;\r
97 +               node->ctx->crypto.decrypt = FALSE;\r
98 +               fprintf (stderr, "Failed to construct gpg context.\n");\r
99 +           }\r
100 +       }\r
101 +    }\r
102 +\r
103      /* Handle PGP/MIME parts */\r
104      if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto.decrypt) {\r
105         if (node->nchildren != 2) {\r
106 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
107 index 997fdd1..a56cf9f 100644\r
108 --- a/notmuch-reply.c\r
109 +++ b/notmuch-reply.c\r
110 @@ -708,25 +708,6 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
111      else\r
112         reply_format_func = notmuch_reply_format_default;\r
113  \r
114 -    if (crypto.decrypt) {\r
115 -#ifdef GMIME_ATLEAST_26\r
116 -       /* TODO: GMimePasswordRequestFunc */\r
117 -       crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
118 -#else\r
119 -       GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
120 -       crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
121 -#endif\r
122 -       if (crypto.gpgctx) {\r
123 -           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto.gpgctx, FALSE);\r
124 -       } else {\r
125 -           crypto.decrypt = FALSE;\r
126 -           fprintf (stderr, "Failed to construct gpg context.\n");\r
127 -       }\r
128 -#ifndef GMIME_ATLEAST_26\r
129 -       g_object_unref (session);\r
130 -#endif\r
131 -    }\r
132 -\r
133      config = notmuch_config_open (ctx, NULL, NULL);\r
134      if (config == NULL)\r
135         return 1;\r
136 diff --git a/notmuch-show.c b/notmuch-show.c\r
137 index 99a10bd..0616f68 100644\r
138 --- a/notmuch-show.c\r
139 +++ b/notmuch-show.c\r
140 @@ -1058,29 +1058,6 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
141         break;\r
142      }\r
143  \r
144 -    if (params.crypto.decrypt || params.crypto.verify) {\r
145 -#ifdef GMIME_ATLEAST_26\r
146 -       /* TODO: GMimePasswordRequestFunc */\r
147 -       params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
148 -#else\r
149 -       GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
150 -       params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
151 -#endif\r
152 -       if (params.crypto.gpgctx) {\r
153 -           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);\r
154 -       } else {\r
155 -           /* If we fail to create the gpgctx set the verify and\r
156 -            * decrypt flags to FALSE so we don't try to do any\r
157 -            * further verification or decryption */\r
158 -           params.crypto.verify = FALSE;\r
159 -           params.crypto.decrypt = FALSE;\r
160 -           fprintf (stderr, "Failed to construct gpg context.\n");\r
161 -       }\r
162 -#ifndef GMIME_ATLEAST_26\r
163 -       g_object_unref (session);\r
164 -#endif\r
165 -    }\r
166 -\r
167      config = notmuch_config_open (ctx, NULL, NULL);\r
168      if (config == NULL)\r
169         return 1;\r
170 -- \r
171 1.7.10\r
172 \r