diff options
author | Gisle Aas <gisle@activestate.com> | 2005-12-28 12:18:58 +0000 |
---|---|---|
committer | Gisle Aas <gisle@activestate.com> | 2005-12-28 12:18:58 +0000 |
commit | 4c8626beeba549aaf3f327729c56a599716ee8b7 (patch) | |
tree | 616a89819fb40ae4eb3333937cc25e6966d6414c /util.c | |
parent | 260d78c9ff623f5d456f7d39acc9715eec2a85f4 (diff) | |
download | perl-4c8626beeba549aaf3f327729c56a599716ee8b7.tar.gz |
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
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 40 |
1 files changed, 17 insertions, 23 deletions
@@ -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; } |