[PATCH] lib: collapse computation of directory_id into a single expression

Subject: [PATCH] lib: collapse computation of directory_id into a single expression

Date: Sat, 27 Dec 2014 09:33:49 +0100

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


According to id:20141226113755.GA64154@pamparam , the lifetime
of (*i).c_str is only guaranteed for that line, so we extract the
information we need in the same line.
---
 lib/message.cc | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index a7a13cc..14e60af 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -639,7 +639,7 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)
 
     for (i.skip_to (direntry_prefix); i != message->doc.termlist_end (); i++) {
 	unsigned int directory_id;
-	const char *direntry, *directory;
+	const char *directory;
 	char *colon;
 
 	/* Terminate loop at first term without desired prefix. */
@@ -649,10 +649,9 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)
 	/* Indicate that there are filenames remaining. */
 	status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
 
-	direntry = (*i).c_str ();
-	direntry += direntry_prefix_len;
-
-	directory_id = strtol (direntry, &colon, 10);
+	directory_id =
+	    strtol ((*i).c_str () + direntry_prefix_len,
+		    &colon, 10);
 
 	if (colon == NULL || *colon != ':')
 	    INTERNAL_ERROR ("malformed direntry");
-- 
2.1.3


Thread: