From: Andy Lester Date: Fri, 9 Dec 2005 11:09:21 +0000 (-0600) Subject: Code tweaks in sv.c X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=00b6aa4170b1d4f8cd86fa0a48749312580e6806;p=p5sagit%2Fp5-mst-13.2.git Code tweaks in sv.c Message-ID: <20051209170921.GC16943@petdance.com> Includes a minor change the patch to account for code that moved elsewhere. p4raw-id: //depot/perl@26317 --- diff --git a/sv.c b/sv.c index 30b499d..19a2ce7 100644 --- a/sv.c +++ b/sv.c @@ -640,8 +640,8 @@ Perl_sv_free_arenas(pTHX) STATIC void * S_more_bodies (pTHX_ size_t size, svtype sv_type) { - void **arena_root = &PL_body_arenaroots[sv_type]; - void **root = &PL_body_roots[sv_type]; + void ** const arena_root = &PL_body_arenaroots[sv_type]; + void ** const root = &PL_body_roots[sv_type]; char *start; const char *end; const size_t count = PERL_ARENA_SIZE / size; @@ -675,7 +675,7 @@ S_more_bodies (pTHX_ size_t size, svtype sv_type) #define new_body_inline(xpv, size, sv_type) \ STMT_START { \ - void **r3wt = &PL_body_roots[sv_type]; \ + void ** const r3wt = &PL_body_roots[sv_type]; \ LOCK_SV_MUTEX; \ xpv = *((void **)(r3wt)) \ ? *((void **)(r3wt)) : S_more_bodies(aTHX_ size, sv_type); \ @@ -704,7 +704,7 @@ S_new_body(pTHX_ size_t size, svtype sv_type) #define del_body(thing, root) \ STMT_START { \ - void **thing_copy = (void **)thing; \ + void ** const thing_copy = (void **)thing;\ LOCK_SV_MUTEX; \ *thing_copy = *root; \ *root = (void*)thing_copy; \ @@ -1413,9 +1413,9 @@ S_not_a_number(pTHX_ SV *sv) /* each *s can expand to 4 chars + "...\0", i.e. need room for 8 chars */ - const char *s, *end; - for (s = SvPVX_const(sv), end = s + SvCUR(sv); s < end && d < limit; - s++) { + const char *s = SvPVX_const(sv); + const char * const end = s + SvCUR(sv); + for ( ; s < end && d < limit; s++ ) { int ch = *s & 0xFF; if (ch & 128 && !isPRINT_LC(ch)) { *d++ = 'M'; @@ -2139,11 +2139,10 @@ Perl_sv_2nv(pTHX_ register SV *sv) if (SvNVX(sv) < (NV)IV_MAX + 0.5) { if (SvIVX(sv) == I_V(nv)) { SvNOK_on(sv); - SvIOK_on(sv); } else { - SvIOK_on(sv); /* It had no "." so it must be integer. */ } + SvIOK_on(sv); } else { /* between IV_MAX and NV(UV_MAX). Could be slightly > UV_MAX */ @@ -2155,10 +2154,8 @@ Perl_sv_2nv(pTHX_ register SV *sv) if (value == nv_as_uv && SvUVX(sv) != UV_MAX) { SvNOK_on(sv); - SvIOK_on(sv); - } else { - SvIOK_on(sv); } + SvIOK_on(sv); } } } @@ -2281,7 +2278,7 @@ S_uiv_2buf(char *buf, IV iv, UV uv, int is_uv, char **peob) static char * S_stringify_regexp(pTHX_ SV *sv, MAGIC *mg, STRLEN *lp) { - const regexp *re = (regexp *)mg->mg_obj; + const regexp * const re = (regexp *)mg->mg_obj; if (!mg->mg_ptr) { const char *fptr = "msix"; @@ -2289,7 +2286,7 @@ S_stringify_regexp(pTHX_ SV *sv, MAGIC *mg, STRLEN *lp) { char ch; int left = 0; int right = 4; - char need_newline = 0; + bool need_newline = 0; U16 reganch = (U16)((re->reganch & PMf_COMPILETIME) >> 12); while((ch = *fptr++)) { @@ -2403,7 +2400,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) } if (SvROK(sv)) { /* XXX Skip this when sv_pvn_force calls */ /* Sneaky stuff here */ - SV *tsv = newSVpvn(tbuf, len); + SV * const tsv = newSVpvn(tbuf, len); sv_2mortal(tsv); if (lp) @@ -2562,7 +2559,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) if (!PL_localizing && !(SvFLAGS(sv) & SVs_PADTMP) && ckWARN(WARN_UNINITIALIZED)) report_uninit(sv); if (lp) - *lp = 0; + *lp = 0; if (SvTYPE(sv) < SVt_PV) /* Typically the caller expects that sv_any is not NULL now. */ sv_upgrade(sv, SVt_PV); @@ -2750,25 +2747,23 @@ Perl_sv_utf8_upgrade_flags(pTHX_ register SV *sv, I32 flags) * had a FLAG in SVs to signal if there are any hibit * chars in the PV. Given that there isn't such a flag * make the loop as fast as possible. */ - const U8 *s = (U8 *) SvPVX_const(sv); + const U8 * const s = (U8 *) SvPVX_const(sv); const U8 * const e = (U8 *) SvEND(sv); const U8 *t = s; - int hibit = 0; while (t < e) { const U8 ch = *t++; - if ((hibit = !NATIVE_IS_INVARIANT(ch))) + /* Check for hi bit */ + if (!NATIVE_IS_INVARIANT(ch)) { + STRLEN len = SvCUR(sv) + 1; /* Plus the \0 */ + U8 * const recoded = bytes_to_utf8((U8*)s, &len); + + SvPV_free(sv); /* No longer using what was there before. */ + SvPV_set(sv, (char*)recoded); + SvCUR_set(sv, len - 1); + SvLEN_set(sv, len); /* No longer know the real size. */ break; - } - if (hibit) { - STRLEN len = SvCUR(sv) + 1; /* Plus the \0 */ - U8 * const recoded = bytes_to_utf8((U8*)s, &len); - - SvPV_free(sv); /* No longer using what was there before. */ - - SvPV_set(sv, (char*)recoded); - SvCUR_set(sv, len - 1); - SvLEN_set(sv, len); /* No longer know the real size. */ + } } /* Mark as UTF-8 even if no hibit - saves scanning loop */ SvUTF8_on(sv); @@ -3400,7 +3395,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) SvIV_set(dstr, SvIVX(sstr)); } if (SvVOK(sstr)) { - MAGIC *smg = mg_find(sstr,PERL_MAGIC_vstring); + const MAGIC * const smg = mg_find(sstr,PERL_MAGIC_vstring); sv_magic(dstr, NULL, PERL_MAGIC_vstring, smg->mg_ptr, smg->mg_len); SvRMAGICAL_on(dstr); @@ -3906,10 +3901,10 @@ and C are implemented in terms of this function. void Perl_sv_catsv_flags(pTHX_ SV *dsv, register SV *ssv, I32 flags) { - const char *spv; - STRLEN slen; if (ssv) { - if ((spv = SvPV_const(ssv, slen))) { + STRLEN slen; + const char *spv = SvPV_const(ssv, slen); + if (spv) { /* sutf8 and dutf8 were type bool, but under USE_ITHREADS, gcc version 2.95.2 20000220 (Debian GNU/Linux) for Linux xxx 2.2.17 on sparc64 with gcc -O2, we erroneously @@ -3927,7 +3922,7 @@ Perl_sv_catsv_flags(pTHX_ SV *dsv, register SV *ssv, I32 flags) if (dutf8 != sutf8) { if (dutf8) { /* Not modifying source SV, so taking a temporary copy. */ - SV* csv = sv_2mortal(newSVpvn(spv, slen)); + SV* const csv = sv_2mortal(newSVpvn(spv, slen)); sv_utf8_upgrade(csv); spv = SvPV_const(csv, slen); @@ -5892,7 +5887,7 @@ thats_really_all_folks: screamer2: if (rslen) { - register const STDCHAR *bpe = buf + sizeof(buf); + register const STDCHAR * const bpe = buf + sizeof(buf); bp = buf; while ((i = PerlIO_getc(fp)) != EOF && (*bp++ = (STDCHAR)i) != rslast && bp < bpe) ; /* keep reading */ @@ -9132,7 +9127,7 @@ Perl_ptr_table_clear(pTHX_ PTR_TBL_t *tbl) PTR_TBL_ENT_t *entry = array[riter]; while (entry) { - PTR_TBL_ENT_t *oentry = entry; + PTR_TBL_ENT_t * const oentry = entry; entry = entry->next; del_pte(oentry); } @@ -9447,8 +9442,8 @@ Perl_sv_dup(pTHX_ SV *sstr, CLONE_PARAMS* param) ++i; } if (SvOOK(sstr)) { - struct xpvhv_aux *saux = HvAUX(sstr); - struct xpvhv_aux *daux = HvAUX(dstr); + struct xpvhv_aux * const saux = HvAUX(sstr); + struct xpvhv_aux * const daux = HvAUX(dstr); /* This flag isn't copied. */ /* SvOOK_on(hv) attacks the IV flags. */ SvFLAGS(dstr) |= SVf_OOK; @@ -11225,7 +11220,7 @@ S_find_uninit_var(pTHX_ OP* obase, SV* uninit_sv, bool match) break; } else { - SV ** const svp = av_fetch((AV*)sv, SvIV(cSVOPx_sv(kid)), FALSE); + SV * const * const svp = av_fetch((AV*)sv, SvIV(cSVOPx_sv(kid)), FALSE); if (!svp || *svp != uninit_sv) break; } @@ -11236,7 +11231,6 @@ S_find_uninit_var(pTHX_ OP* obase, SV* uninit_sv, bool match) else return varname(gv, '@', o->op_targ, Nullsv, SvIV(cSVOPx_sv(kid)), FUV_SUBSCRIPT_ARRAY); - ; } else { /* index is an expression;