From: Gisle Aas Date: Wed, 28 Dec 2005 12:18:58 +0000 (+0000) Subject: Leaner ninstr(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4c8626beeba549aaf3f327729c56a599716ee8b7;p=p5sagit%2Fp5-mst-13.2.git Leaner ninstr(). The compiled function ended up 37% smaller on Linux/gcc. I ought to be faster as well, but I did not try to measure that. p4raw-id: //depot/perl@26511 --- diff --git a/util.c b/util.c index c082f5b..d681d04 100644 --- a/util.c +++ b/util.c @@ -351,30 +351,24 @@ Perl_instr(pTHX_ register const char *big, register const char *little) /* same as instr but allow embedded nulls */ char * -Perl_ninstr(pTHX_ register const char *big, register const char *bigend, const char *little, const char *lend) +Perl_ninstr(pTHX_ const char *big, const char *bigend, const char *little, const char *lend) { - register const I32 first = *little; - register const char * const littleend = lend; - - if (little >= littleend) - return (char*)big; - if (bigend - big < littleend - little) - return Nullch; - bigend -= littleend - little++; - while (big <= bigend) { - register const char *s, *x; - if (*big++ != first) - continue; - for (x=big,s=little; s < littleend; /**/ ) { - if (*s != *x) - break; - else { - s++; - x++; - } - } - if (s >= littleend) - return (char*)(big-1); + if (little >= lend) + return (char*)big; + { + char first = *little++; + const char *s, *x; + bigend -= lend - little; + OUTER: + while (big <= bigend) { + if (*big++ != first) + goto OUTER; + for (x=big,s=little; s < lend; x++,s++) { + if (*s != *x) + goto OUTER; + } + return (char*)(big-1); + } } return Nullch; }