git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Remove uneccessary strncmp call in imap-send count_messages

From
APAndy Parkins <andyparkins@gmail.com>
Date
Oct 22, 2006, 14:53 UTC
Message-ID
<200610221553.28872.andyparkins@gmail.com>

The strncmp() call in count_messages() was doing the same comparison that strstr() did, so there was no need to call it. A little rewrite and count_messages() is simpler.

Obviously no huge benefit, as it's not frequently called. I'm just getting familiar with git.

Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
 imap-send.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index 16804ab..cfac17b 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1198,15 +1198,14 @@ count_messages( msg_data_t *msg )
 	int count = 0;
 	char *p = msg->data;
 
-	while (1) {
-		if (!strncmp( "From ", p, 5 )) {
-			count++;
+	while (p) {
+		p = strstr( p, "From " );
+		if ( p != NULL ) {
+			if ( p == msg->data || *(p-1) == '\n' ) {
+				count++;
+			}
 			p += 5;
 		}
-		p = strstr( p+5, "\nFrom ");
-		if (!p)
-			break;
-		p++;
 	}
 	return count;
 }
-- 
1.4.2.3
Message 1 of 1 in “Remove uneccessary strncmp call in imap-send count_messages”
  1. Remove uneccessary strncmp call in imap-send count_messagesAndy Parkins, Oct 22, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.