summaryrefslogtreecommitdiff
path: root/doio.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2014-03-02 10:02:51 +0100
committerNicholas Clark <nick@ccl4.org>2014-03-19 10:57:53 +0100
commitd8015975ab8da00c47775a05a91a9d72f379bf1b (patch)
tree76edf5fc52d04f1504378bf7d0d3aa98b1ad0782 /doio.c
parentd5eb9a4687ba974ffd0d02aab53326c5aba6a9e0 (diff)
downloadperl-d8015975ab8da00c47775a05a91a9d72f379bf1b.tar.gz
Simplify the code in Perl_nextargv().
Split the ternary that called Perl_do_open_raw() and Perl_do_open6() based on PL_inplace into two different if blocks, and merge these with the following code which is also conditional on PL_inplace. Remove the warning code from an else block and re-indent it, to make it clear that it is always called if control reaches the end of the while loop.
Diffstat (limited to 'doio.c')
-rw-r--r--doio.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/doio.c b/doio.c
index 1629227853..07a4cb83bf 100644
--- a/doio.c
+++ b/doio.c
@@ -827,17 +827,23 @@ Perl_nextargv(pTHX_ GV *gv)
return NULL;
while (av_tindex(GvAV(gv)) >= 0) {
STRLEN oldlen;
- bool success;
sv = av_shift(GvAV(gv));
SAVEFREESV(sv);
SvTAINTED_off(GvSVn(gv)); /* previous tainting irrelevant */
sv_setsv(GvSVn(gv),sv);
SvSETMAGIC(GvSV(gv));
PL_oldname = SvPVx(GvSV(gv), oldlen);
- success = PL_inplace ? do_open_raw(gv, PL_oldname, oldlen, O_RDONLY, 0)
- : do_open6(gv, PL_oldname, oldlen, NULL, NULL, 0);
- if (success) {
- if (PL_inplace) {
+ if (LIKELY(!PL_inplace)) {
+ if (do_open6(gv, PL_oldname, oldlen, NULL, NULL, 0)) {
+ return IoIFP(GvIOp(gv));
+ }
+ }
+ else {
+ /* This very long block ends with return IoIFP(GvIOp(gv));
+ Both this block and the block above fall through on open
+ failure to the warning code, and then the while loop above tries
+ the next entry. */
+ if (do_open_raw(gv, PL_oldname, oldlen, O_RDONLY, 0)) {
TAINT_PROPER("inplace open");
if (oldlen == 1 && *PL_oldname == '-') {
setdefout(gv_fetchpvs("STDOUT", GV_ADD|GV_NOTQUAL,
@@ -968,23 +974,22 @@ Perl_nextargv(pTHX_ GV *gv)
/* XXX silently ignore failures */
PERL_UNUSED_VAR(rc);
}
+ return IoIFP(GvIOp(gv));
}
- return IoIFP(GvIOp(gv));
- }
- else {
- if (ckWARN_d(WARN_INPLACE)) {
- const int eno = errno;
- if (PerlLIO_stat(PL_oldname, &PL_statbuf) >= 0
- && !S_ISREG(PL_statbuf.st_mode))
- {
- Perl_warner(aTHX_ packWARN(WARN_INPLACE),
- "Can't do inplace edit: %s is not a regular file",
- PL_oldname);
- }
- else
- Perl_warner(aTHX_ packWARN(WARN_INPLACE), "Can't open %s: %s",
- PL_oldname, Strerror(eno));
- }
+ } /* successful do_open_raw(), PL_inplace non-NULL */
+
+ if (ckWARN_d(WARN_INPLACE)) {
+ const int eno = errno;
+ if (PerlLIO_stat(PL_oldname, &PL_statbuf) >= 0
+ && !S_ISREG(PL_statbuf.st_mode)) {
+ Perl_warner(aTHX_ packWARN(WARN_INPLACE),
+ "Can't do inplace edit: %s is not a regular file",
+ PL_oldname);
+ }
+ else {
+ Perl_warner(aTHX_ packWARN(WARN_INPLACE), "Can't open %s: %s",
+ PL_oldname, Strerror(eno));
+ }
}
}
if (io && (IoFLAGS(io) & IOf_ARGV))