From b606cf7f37b8b46206c7f521b29167e037397a62 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Tue, 28 Jun 2011 12:17:38 +0200 Subject: [PATCH] Store C's data as U32s, instead of I32s. The "no more" condition is now represented as ~0, instead of -1. --- pp.c | 21 ++++++++------------- regexec.c | 2 +- util.c | 21 +++++++++++---------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/pp.c b/pp.c index 12ab913..f177165 100644 --- a/pp.c +++ b/pp.c @@ -707,9 +707,8 @@ PP(pp_study) { dVAR; dSP; dPOPss; register unsigned char *s; - register I32 ch; - register I32 *sfirst; - register I32 *snext; + U32 *sfirst; + U32 *snext; STRLEN len; MAGIC *mg = SvMAGICAL(sv) ? mg_find(sv, PERL_MAGIC_study) : NULL; @@ -729,7 +728,7 @@ PP(pp_study) RETPUSHNO; } - Newx(sfirst, 256 + len, I32); + Newx(sfirst, 256 + len, U32); if (!sfirst) DIE(aTHX_ "do_study: out of memory"); @@ -738,19 +737,15 @@ PP(pp_study) if (!mg) mg = sv_magicext(sv, NULL, PERL_MAGIC_study, &PL_vtbl_regexp, NULL, 0); mg->mg_ptr = (char *) sfirst; - mg->mg_len = (256 + len) * sizeof(I32); + mg->mg_len = (256 + len) * sizeof(U32); - snext = sfirst; - for (ch = 256; ch; --ch) - *snext++ = -1; + snext = sfirst + 256; + memset(sfirst, ~0, 256 * sizeof(U32)); while (len-- > 0) { const U8 ch = s[len]; - if (sfirst[ch] >= 0) - snext[len] = sfirst[ch]; - else - snext[len] = -1; - sfirst[ch] = (I32)len; + snext[len] = sfirst[ch]; + sfirst[ch] = len; } RETPUSHYES; diff --git a/regexec.c b/regexec.c index b9677ec..516bf95 100644 --- a/regexec.c +++ b/regexec.c @@ -701,7 +701,7 @@ Perl_re_intuit_start(pTHX_ REGEXP * const rx, SV *sv, char *strpos, mg = mg_find(sv, PERL_MAGIC_study); assert(mg); - if (((I32 *)mg->mg_ptr)[BmRARE(check)] != -1 + if (((U32 *)mg->mg_ptr)[BmRARE(check)] != (U32)~0 || ( BmRARE(check) == '\n' && (BmPREVIOUS(check) == SvCUR(check) - 1) && SvTAIL(check) )) diff --git a/util.c b/util.c index 929c776..4dbd15e 100644 --- a/util.c +++ b/util.c @@ -854,7 +854,7 @@ Perl_screaminstr(pTHX_ SV *bigstr, SV *littlestr, I32 start_shift, I32 end_shift { dVAR; register const unsigned char *big; - register I32 pos; + U32 pos; register I32 previous; register I32 first; register const unsigned char *little; @@ -862,8 +862,9 @@ Perl_screaminstr(pTHX_ SV *bigstr, SV *littlestr, I32 start_shift, I32 end_shift register const unsigned char *littleend; bool found = FALSE; const MAGIC * mg; - I32 *screamfirst; - I32 *screamnext; + U32 *screamfirst; + U32 *screamnext; + U32 const nope = ~0; PERL_ARGS_ASSERT_SCREAMINSTR; @@ -873,12 +874,12 @@ Perl_screaminstr(pTHX_ SV *bigstr, SV *littlestr, I32 start_shift, I32 end_shift assert(SvTYPE(littlestr) == SVt_PVMG); assert(SvVALID(littlestr)); - screamfirst = (I32 *)mg->mg_ptr; + screamfirst = (U32 *)mg->mg_ptr; screamnext = screamfirst + 256; pos = *old_posp == -1 ? screamfirst[BmRARE(littlestr)] : screamnext[*old_posp]; - if (pos == -1) { + if (pos == nope) { cant_find: if ( BmRARE(littlestr) == '\n' && BmPREVIOUS(littlestr) == SvCUR(littlestr) - 1) { @@ -909,14 +910,14 @@ Perl_screaminstr(pTHX_ SV *bigstr, SV *littlestr, I32 start_shift, I32 end_shift #endif return NULL; } - while (pos < previous + start_shift) { + while ((I32)pos < previous + start_shift) { pos = screamnext[pos]; - if (pos == -1) + if (pos == nope) goto cant_find; } big -= previous; do { - if (pos >= stop_pos) break; + if ((I32)pos >= stop_pos) break; if (big[pos] == first) { const unsigned char *s = little; const unsigned char *x = big + pos + 1; @@ -926,13 +927,13 @@ Perl_screaminstr(pTHX_ SV *bigstr, SV *littlestr, I32 start_shift, I32 end_shift ++s; } if (s == littleend) { - *old_posp = pos; + *old_posp = (I32)pos; if (!last) return (char *)(big+pos); found = TRUE; } } pos = screamnext[pos]; - } while (pos != -1); + } while (pos != nope); if (last && found) return (char *)(big+(*old_posp)); check_tail: -- 2.7.4