This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Simplify S_set_caret_X() by returning early if we set caret_x.
authorNicholas Clark <nick@ccl4.org>
Tue, 13 Sep 2011 19:58:56 +0000 (21:58 +0200)
committerNicholas Clark <nick@ccl4.org>
Wed, 14 Sep 2011 09:26:36 +0000 (11:26 +0200)
This avoids duplicating the fallback code to set caret_x to PL_origargv[0].

perl.c

diff --git a/perl.c b/perl.c
index 32d47dd..fa88566 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1395,7 +1395,10 @@ S_set_caret_X(pTHX) {
     GV* tmpgv = gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL, SVt_PV); /* $^X */
     if (tmpgv) {
        SV *const caret_x = GvSV(tmpgv);
-#ifdef HAS_PROCSELFEXE
+#if defined(OS2)
+       sv_setpv(caret_x, os2_execname(aTHX));
+#else
+#  ifdef HAS_PROCSELFEXE
        char buf[MAXPATHLEN];
        int len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1);
 
@@ -1417,17 +1420,12 @@ S_set_caret_X(pTHX) {
        */
        if (len > 0 && memchr(buf, '/', len)) {
            sv_setpvn(caret_x, buf, len);
+           return;
        }
-       else {
-           sv_setpv(caret_x, PL_origargv[0]);
-       }
-#else
-#ifdef OS2
-       sv_setpv(caret_x, os2_execname(aTHX));
-#else
+#  endif
+       /* Fallback to this:  */
        sv_setpv(caret_x, PL_origargv[0]);
 #endif
-#endif
     }
 }