Performance: use memchr to find the next '-' and then call memcmp to check whether...
authorWilfried Goesgens <dothebart@citadel.org>
Tue, 7 Dec 2010 22:20:43 +0000 (23:20 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Tue, 7 Dec 2010 22:20:43 +0000 (23:20 +0100)
 - we fast forward to the next '-' since every mime boundary starts with '-'
 - from a '-' we check thorough whether at this point we can find the searched boundary

Thanks to cirrus for pointing me to memchr()

libcitadel/lib/mime_parser.c

index 3b10588b7a3fc2c0413fc89790bca71f0e762690..7e4cbfb222ba3df3f447dfcd6474d6e7295caee8 100644 (file)
@@ -536,8 +536,13 @@ static char *FindNextContent(char *ptr,
                        if (pptr < content_end)
                                ptr = pptr;
                }
+               
+
                next_boundary = NULL;
-               for (srch=ptr; srch<content_end; ++srch) {
+               for (srch=ptr; 
+                    (srch != NULL) && (srch < content_end); 
+                    srch = memchr(srch, '-',  content_end - srch)) 
+               {
                        if (!memcmp(srch, 
                                    m->b[startary].Key, 
                                    m->b[startary].len)) 
@@ -545,6 +550,8 @@ static char *FindNextContent(char *ptr,
                                next_boundary = srch;
                                srch = content_end;
                        }
+                       else srch ++;
+
                }
 
        }