This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
av_fetch: de-duplicate small bit of code
authorDavid Mitchell <davem@iabyn.com>
Mon, 27 Feb 2012 11:32:36 +0000 (11:32 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 27 Feb 2012 11:32:36 +0000 (11:32 +0000)
make the code slightly smaller by changing

    if (A)
return X;
    if (B)
return X;

into
    `
    if (A || B)
return X;

av.c

diff --git a/av.c b/av.c
index 1114531..aada6c6 100644 (file)
--- a/av.c
+++ b/av.c
@@ -249,18 +249,12 @@ Perl_av_fetch(pTHX_ register AV *av, I32 key, I32 lval)
            return NULL;
     }
 
            return NULL;
     }
 
-    if (key > AvFILLp(av)) {
-       if (!lval)
-           return NULL;
-       return av_store(av,key,newSV(0));
-    }
-    if (AvARRAY(av)[key] == &PL_sv_undef) {
-    emptyness:
-       if (lval)
-           return av_store(av,key,newSV(0));
-       return NULL;
+    if (key > AvFILLp(av) || AvARRAY(av)[key] == &PL_sv_undef) {
+      emptyness:
+       return lval ? av_store(av,key,newSV(0)) : NULL;
     }
     }
-    else if (AvREIFY(av)
+
+    if (AvREIFY(av)
             && (!AvARRAY(av)[key]      /* eg. @_ could have freed elts */
                 || SvIS_FREED(AvARRAY(av)[key]))) {
        AvARRAY(av)[key] = &PL_sv_undef;        /* 1/2 reify */
             && (!AvARRAY(av)[key]      /* eg. @_ could have freed elts */
                 || SvIS_FREED(AvARRAY(av)[key]))) {
        AvARRAY(av)[key] = &PL_sv_undef;        /* 1/2 reify */