From: Andy Lester <andy@petdance.com>
Date: Wed, 24 May 2006 00:16:40 +0000 (-0500)
Subject: Refactoring in av.c
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e2d306cb6f7ec064f0604b24211e7b2cd0705b39;p=p5sagit%2Fp5-mst-13.2.git

Refactoring in av.c
Message-ID: <20060524051640.GA4713@petdance.com>

p4raw-id: //depot/perl@28296
---

diff --git a/av.c b/av.c
index 5f04d05..4692e6b 100644
--- a/av.c
+++ b/av.c
@@ -42,7 +42,7 @@ Perl_av_reify(pTHX_ AV *av)
 	SV * const sv = AvARRAY(av)[--key];
 	assert(sv);
 	if (sv != &PL_sv_undef)
-	    SvREFCNT_inc_void_NN(sv);
+	    SvREFCNT_inc_simple_void_NN(sv);
     }
     key = AvARRAY(av) - AvALLOC(av);
     while (key)
@@ -194,32 +194,31 @@ SV**
 Perl_av_fetch(pTHX_ register AV *av, I32 key, I32 lval)
 {
     dVAR;
-    SV *sv;
 
     assert(av);
 
     if (SvRMAGICAL(av)) {
         const MAGIC * const tied_magic = mg_find((SV*)av, PERL_MAGIC_tied);
         if (tied_magic || mg_find((SV*)av, PERL_MAGIC_regdata)) {
-            U32 adjust_index = 1;
-
-            if (tied_magic && key < 0) {
-                /* Handle negative array indices 20020222 MJD */
-		SV * const * const negative_indices_glob =
-                    hv_fetch(SvSTASH(SvRV(SvTIED_obj((SV *)av, 
-                                                     tied_magic))), 
-                             NEGATIVE_INDICES_VAR, 16, 0);
+	    SV *sv;
+	    if (key < 0) {
+		I32 adjust_index = 1;
+		if (tied_magic) {
+		    /* Handle negative array indices 20020222 MJD */
+		    SV * const * const negative_indices_glob =
+			hv_fetch(SvSTASH(SvRV(SvTIED_obj((SV *)av, tied_magic))),
+				NEGATIVE_INDICES_VAR, 16, 0);
 
-                if (negative_indices_glob
-                    && SvTRUE(GvSV(*negative_indices_glob)))
-                    adjust_index = 0;
-            }
+		    if (negative_indices_glob && SvTRUE(GvSV(*negative_indices_glob)))
+			adjust_index = 0;
+		}
 
-            if (key < 0 && adjust_index) {
-                key += AvFILL(av) + 1;
-                if (key < 0)
-                    return 0;
-            }
+		if (adjust_index) {
+		    key += AvFILL(av) + 1;
+		    if (key < 0)
+			return NULL;
+		}
+	    }
 
             sv = sv_newmortal();
 	    sv_upgrade(sv, SVt_PVLV);
@@ -233,22 +232,19 @@ Perl_av_fetch(pTHX_ register AV *av, I32 key, I32 lval)
     if (key < 0) {
 	key += AvFILL(av) + 1;
 	if (key < 0)
-	    return 0;
+	    return NULL;
     }
 
     if (key > AvFILLp(av)) {
 	if (!lval)
-	    return 0;
-	sv = newSV(0);
-	return av_store(av,key,sv);
+	    return NULL;
+	return av_store(av,key,newSV(0));
     }
     if (AvARRAY(av)[key] == &PL_sv_undef) {
     emptyness:
-	if (lval) {
-	    sv = newSV(0);
-	    return av_store(av,key,sv);
-	}
-	return 0;
+	if (lval)
+	    return av_store(av,key,newSV(0));
+	return NULL;
     }
     else if (AvREIFY(av)
 	     && (!AvARRAY(av)[key]	/* eg. @_ could have freed elts */
@@ -296,7 +292,7 @@ Perl_av_store(pTHX_ register AV *av, I32 key, SV *val)
         if (tied_magic) {
             /* Handle negative array indices 20020222 MJD */
             if (key < 0) {
-                unsigned adjust_index = 1;
+		bool adjust_index = 1;
 		SV * const * const negative_indices_glob =
                     hv_fetch(SvSTASH(SvRV(SvTIED_obj((SV *)av, 
                                                      tied_magic))), 
@@ -313,7 +309,7 @@ Perl_av_store(pTHX_ register AV *av, I32 key, SV *val)
 	    if (val != &PL_sv_undef) {
 		mg_copy((SV*)av, val, 0, key);
 	    }
-	    return 0;
+	    return NULL;
         }
     }
 
@@ -321,7 +317,7 @@ Perl_av_store(pTHX_ register AV *av, I32 key, SV *val)
     if (key < 0) {
 	key += AvFILL(av) + 1;
 	if (key < 0)
-	    return 0;
+	    return NULL;
     }
 
     if (SvREADONLY(av) && key >= AvFILL(av))
@@ -336,9 +332,9 @@ Perl_av_store(pTHX_ register AV *av, I32 key, SV *val)
 	if (!AvREAL(av)) {
 	    if (av == PL_curstack && key > PL_stack_sp - PL_stack_base)
 		PL_stack_sp = PL_stack_base + key;	/* XPUSH in disguise */
-	    do
+	    do {
 		ary[++AvFILLp(av)] = &PL_sv_undef;
-	    while (AvFILLp(av) < key);
+	    } while (AvFILLp(av) < key);
 	}
 	AvFILLp(av) = key;
     }
@@ -424,7 +420,7 @@ void
 Perl_av_clear(pTHX_ register AV *av)
 {
     dVAR;
-    register I32 key;
+    I32 extra;
 
     assert(av);
 #ifdef DEBUGGING
@@ -445,17 +441,18 @@ Perl_av_clear(pTHX_ register AV *av)
 
     if (AvREAL(av)) {
 	SV** const ary = AvARRAY(av);
-	key = AvFILLp(av) + 1;
-	while (key) {
-	    SV * const sv = ary[--key];
+	I32 index = AvFILLp(av) + 1;
+	while (index) {
+	    SV * const sv = ary[--index];
 	    /* undef the slot before freeing the value, because a
-	     * destructor might try to modify this arrray */
-	    ary[key] = &PL_sv_undef;
+	     * destructor might try to modify this array */
+	    ary[index] = &PL_sv_undef;
 	    SvREFCNT_dec(sv);
 	}
     }
-    if ((key = AvARRAY(av) - AvALLOC(av))) {
-	AvMAX(av) += key;
+    extra = AvARRAY(av) - AvALLOC(av);
+    if (extra) {
+	AvMAX(av) += extra;
 	SvPV_set(av, (char*)AvALLOC(av));
     }
     AvFILLp(av) = -1;
diff --git a/cop.h b/cop.h
index c11687d..83f1f04 100644
--- a/cop.h
+++ b/cop.h
@@ -330,7 +330,7 @@ struct block_sub {
 	    POP_SAVEARRAY();						\
 	    /* abandon @_ if it got reified */				\
 	    if (AvREAL(cx->blk_sub.argarray)) {				\
-		SSize_t fill = AvFILLp(cx->blk_sub.argarray);		\
+		const SSize_t fill = AvFILLp(cx->blk_sub.argarray);	\
 		SvREFCNT_dec(cx->blk_sub.argarray);			\
 		cx->blk_sub.argarray = newAV();				\
 		av_extend(cx->blk_sub.argarray, fill);			\