From: Ralph Corderoy Date: Sat, 12 Nov 2016 00:39:23 +0000 (+0000) Subject: m_getfld: Replace matchc() with memmem(3). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/c2306df99ac5f27147cf1fdba2935700fb008d72?ds=inline m_getfld: Replace matchc() with memmem(3). 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. --- diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 338ea16e..c0605b4d 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -204,7 +204,6 @@ */ 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; - } -}