From: Andy Lester Date: Tue, 2 May 2006 13:38:15 +0000 (-0500) Subject: clean up loops in doio.c and dump.c X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=294b3b3940051144b7e617afd7d93672b0fc2dfd;p=p5sagit%2Fp5-mst-13.2.git clean up loops in doio.c and dump.c Message-ID: <20060502183815.GA7979@petdance.com> p4raw-id: //depot/perl@28077 --- diff --git a/doio.c b/doio.c index e1cc258..a7dc9d9 100644 --- a/doio.c +++ b/doio.c @@ -195,7 +195,8 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, SAVEFREEPV(type); /* Lose leading and trailing white space */ - for (; isSPACE(*type); type++) ; + while (isSPACE(*type)) + type++; while (tend > type && isSPACE(tend[-1])) *--tend = '\0'; @@ -234,7 +235,9 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } type++; } - for (type++; isSPACE(*type); type++) ; + do { + type++; + } while (isSPACE(*type)); if (!num_svs) { name = type; len = tend-type; @@ -321,7 +324,8 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, if (num_svs > 1) { Perl_croak(aTHX_ "More than one argument to '%c&' open",IoTYPE(io)); } - for (; isSPACE(*type); type++) ; + while (isSPACE(*type)) + type++; if (num_svs && (SvIOK(*svp) || (SvPOK(*svp) && looks_like_number(*svp)))) { fd = SvUV(*svp); num_svs = 0; @@ -398,7 +402,8 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } } /* & */ else { - for (; isSPACE(*type); type++) ; + while (isSPACE(*type)) + type++; if (*type == IoTYPE_STD && (!type[1] || isSPACE(type[1]) || type[1] == ':')) { type++; fp = PerlIO_stdout(); @@ -421,7 +426,9 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, goto unknown_open_mode; } /* IoTYPE_WRONLY */ else if (*type == IoTYPE_RDONLY) { - for (type++; isSPACE(*type); type++) ; + do { + type++; + } while (isSPACE(*type)); mode[0] = 'r'; #ifdef HAS_STRLCAT if (in_raw) @@ -504,7 +511,8 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } IoTYPE(io) = IoTYPE_PIPE; if (num_svs) { - for (; isSPACE(*type); type++) ; + while (isSPACE(*type)) + type++; if (*type) { if (PerlIO_apply_layers(aTHX_ fp, mode, type) != 0) { goto say_false; @@ -740,7 +748,8 @@ Perl_nextargv(pTHX_ register GV *gv) if (PL_inplace) { if (!PL_argvout_stack) PL_argvout_stack = newAV(); - av_push(PL_argvout_stack, SvREFCNT_inc_simple(PL_defoutgv)); + assert(PL_defoutgv); + av_push(PL_argvout_stack, SvREFCNT_inc_simple_NN(PL_defoutgv)); } } if (PL_filemode & (S_ISUID|S_ISGID)) { @@ -1518,7 +1527,9 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) if (strnEQ(cmd,"exec",4) && isSPACE(cmd[4])) goto doshell; - for (s = cmd; *s && isALNUM(*s); s++) ; /* catch VAR=val gizmo */ + s = cmd; + while (isALNUM(*s)) + s++; /* catch VAR=val gizmo */ if (*s == '=') goto doshell; @@ -1556,10 +1567,12 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) PL_Cmd = savepvn(cmd, s-cmd); a = PL_Argv; for (s = PL_Cmd; *s;) { - while (*s && isSPACE(*s)) s++; + while (isSPACE(*s)) + s++; if (*s) *(a++) = s; - while (*s && !isSPACE(*s)) s++; + while (*s && !isSPACE(*s)) + s++; if (*s) *s++ = '\0'; } diff --git a/dump.c b/dump.c index e475a0f..a8d362a 100644 --- a/dump.c +++ b/dump.c @@ -423,11 +423,7 @@ STATIC void S_sequence(pTHX_ register const OP *o) { dVAR; - SV *op; - const char *key; - STRLEN len; const OP *oldop = NULL; - OP *l; if (!o) return; @@ -441,8 +437,10 @@ S_sequence(pTHX_ register const OP *o) Sequence = newHV(); for (; o; o = o->op_next) { - op = newSVuv(PTR2UV(o)); - key = SvPV_const(op, len); + STRLEN len; + SV * const op = newSVuv(PTR2UV(o)); + const char * const key = SvPV_const(op, len); + if (hv_exists(Sequence, key, len)) break; @@ -481,32 +479,22 @@ S_sequence(pTHX_ register const OP *o) case OP_COND_EXPR: case OP_RANGE: hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0); - for (l = cLOGOPo->op_other; l && l->op_type == OP_NULL; l = l->op_next) - ; - sequence(l); + sequence_tail(cLOGOPo->op_other); break; case OP_ENTERLOOP: case OP_ENTERITER: hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0); - for (l = cLOOPo->op_redoop; l && l->op_type == OP_NULL; l = l->op_next) - ; - sequence(l); - for (l = cLOOPo->op_nextop; l && l->op_type == OP_NULL; l = l->op_next) - ; - sequence(l); - for (l = cLOOPo->op_lastop; l && l->op_type == OP_NULL; l = l->op_next) - ; - sequence(l); + sequence_tail(cLOOPo->op_redoop); + sequence_tail(cLOOPo->op_nextop); + sequence_tail(cLOOPo->op_lastop); break; case OP_QR: case OP_MATCH: case OP_SUBST: hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0); - for (l = cPMOPo->op_pmreplstart; l && l->op_type == OP_NULL; l = l->op_next) - ; - sequence(l); + sequence_tail(cPMOPo->op_pmreplstart); break; case OP_HELEM: @@ -520,6 +508,14 @@ S_sequence(pTHX_ register const OP *o) } } +static void +S_sequence_tail(pTHX_ const OP *o) +{ + while (o && (o->op_type == OP_NULL)) + o = o->op_next; + sequence(o); +} + STATIC UV S_sequence_num(pTHX_ const OP *o) { diff --git a/embed.fnc b/embed.fnc index 02feb65..3abf027 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1340,6 +1340,7 @@ Es |void |to_byte_substr |NN regexp * prog s |CV* |deb_curcv |I32 ix s |void |debprof |NN const OP *o s |void |sequence |NULLOK const OP *o +s |void |sequence_tail |NULLOK const OP *o s |UV |sequence_num |NULLOK const OP *o s |SV* |pm_description |NN const PMOP *pm #endif diff --git a/embed.h b/embed.h index ed3f5b3..7304c55 100644 --- a/embed.h +++ b/embed.h @@ -1354,6 +1354,7 @@ #define deb_curcv S_deb_curcv #define debprof S_debprof #define sequence S_sequence +#define sequence_tail S_sequence_tail #define sequence_num S_sequence_num #define pm_description S_pm_description #endif @@ -3512,6 +3513,7 @@ #define deb_curcv(a) S_deb_curcv(aTHX_ a) #define debprof(a) S_debprof(aTHX_ a) #define sequence(a) S_sequence(aTHX_ a) +#define sequence_tail(a) S_sequence_tail(aTHX_ a) #define sequence_num(a) S_sequence_num(aTHX_ a) #define pm_description(a) S_pm_description(aTHX_ a) #endif diff --git a/proto.h b/proto.h index dcffdaf..db1b75f 100644 --- a/proto.h +++ b/proto.h @@ -3681,6 +3681,7 @@ STATIC void S_debprof(pTHX_ const OP *o) __attribute__nonnull__(pTHX_1); STATIC void S_sequence(pTHX_ const OP *o); +STATIC void S_sequence_tail(pTHX_ const OP *o); STATIC UV S_sequence_num(pTHX_ const OP *o); STATIC SV* S_pm_description(pTHX_ const PMOP *pm) __attribute__nonnull__(pTHX_1);