]> diplodocus.org Git - nmh/commitdiff
m_getfld: Replace matchc() with memmem(3).
authorRalph Corderoy <ralph@inputplus.co.uk>
Sat, 12 Nov 2016 00:39:23 +0000 (00:39 +0000)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sat, 12 Nov 2016 00:39:23 +0000 (00:39 +0000)
libc is more likely to find one lump of memory inside another quicker
than a home-grown quadratic emulation of the VAX's MATCHC instruction.
memmem() isn't POSIX, but exists on Linux and FreeBSD.  This will see if
the buildbot is happy.

sbr/m_getfld.c

index 338ea16..c0605b4 100644 (file)
  */
 struct m_getfld_state;
 static int m_Eom (m_getfld_state_t);
-static char *matchc(int, char *, int, char *);
 
 #define eom(c,s)       (s->msg_style != MS_DEFAULT && \
                         ((c) == *s->msg_delim && m_Eom(s)))
@@ -681,7 +680,7 @@ m_getfld (m_getfld_state_t *gstate, char name[NAMESZ], char *buf, int *bufsz,
                 */
                char *ep;
 
-               if ((ep = matchc( s->fdelimlen, s->fdelim, c, bp )))
+                if ((ep = memmem(bp, c, s->fdelim, s->fdelimlen)))
                    c = ep - bp + 1;
                else {
                    /*
@@ -892,25 +891,3 @@ m_Eom (m_getfld_state_t s)
 
     return 1;
 }
-
-
-static char *
-matchc(int patln, char *pat, int strln, char *str)
-{
-       char *es = str + strln - patln;
-       char *sp;
-       char *pp;
-       char *ep = pat + patln;
-       char pc = *pat++;
-
-       for(;;) {
-               while (pc != *str++)
-                       if (str > es)
-                               return 0;
-               sp = str; pp = pat;
-               while (pp < ep && *sp++ == *pp)
-                       pp++;
-               if (pp >= ep)
-                       return --str;
-       }
-}