summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-05-17 13:16:57 +0100
committerNicholas Clark <nick@ccl4.org>2011-06-11 09:40:02 +0200
commit21aeb718e9b2ffc24ed853a11c571efa7fc3555d (patch)
tree2cde2e338fb91b391ab9e2cb856d2ea2b49f78af /util.c
parentea725ce6fd46ebc3bd7040373b9c0721af8813f8 (diff)
downloadperl-21aeb718e9b2ffc24ed853a11c571efa7fc3555d.tar.gz
In Perl_fbm_instr(), use a switch() statement for the special case code.
Previously the special-case code for lengths 0, 1 and 2 was in a nested set of if() statements, which was slightly cryptic to read.
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/util.c b/util.c
index 7341117176..74d7bb8dec 100644
--- a/util.c
+++ b/util.c
@@ -573,6 +573,8 @@ Perl_fbm_compile(pTHX_ SV *sv, U32 flags)
SvNOK_off(sv);
SvVALID_on(sv);
if (len > 2) {
+ /* Shorter strings are special-cased in Perl_fbm_instr(), and don't use
+ the BM table. */
const unsigned char *sb;
const U8 mlen = (len>255) ? 255 : (U8)len;
register U8 *table;
@@ -647,9 +649,10 @@ Perl_fbm_instr(pTHX_ unsigned char *big, register unsigned char *bigend, SV *lit
return NULL;
}
- if (littlelen <= 2) { /* Special-cased */
-
- if (littlelen == 1) {
+ switch (littlelen) { /* Special cases for 0, 1 and 2 */
+ case 0:
+ return (char*)big; /* Cannot be SvTAIL! */
+ case 1:
if (SvTAIL(littlestr) && !multiline) { /* Anchor only! */
/* Know that bigend != big. */
if (bigend[-1] == '\n')
@@ -665,11 +668,7 @@ Perl_fbm_instr(pTHX_ unsigned char *big, register unsigned char *bigend, SV *lit
if (SvTAIL(littlestr))
return (char *) bigend;
return NULL;
- }
- if (!littlelen)
- return (char*)big; /* Cannot be SvTAIL! */
-
- /* littlelen is 2 */
+ case 2:
if (SvTAIL(littlestr) && !multiline) {
if (bigend[-1] == '\n' && bigend[-2] == *little)
return (char*)bigend - 2;
@@ -729,7 +728,10 @@ Perl_fbm_instr(pTHX_ unsigned char *big, register unsigned char *bigend, SV *lit
if (SvTAIL(littlestr) && (*bigend == *little))
return (char *)bigend; /* bigend is already decremented. */
return NULL;
+ default:
+ break; /* Only lengths 0 1 and 2 have special-case code. */
}
+
if (SvTAIL(littlestr) && !multiline) { /* tail anchored? */
s = bigend - littlelen;
if (s >= big && bigend[-1] == '\n' && *s == *little