Simplify S_add_data(), given that realloc will NULL acts as malloc().
Nicholas Clark [Sun, 26 Nov 2006 18:44:57 +0000 (18:44 +0000)]
p4raw-id: //depot/perl@29387

regcomp.c

index 7297eb6..320127c 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -3863,22 +3863,18 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
 STATIC U32
 S_add_data(RExC_state_t *pRExC_state, U32 n, const char *s)
 {
-    if (RExC_rxi->data) {
-       const U32 count = RExC_rxi->data->count;
-       Renewc(RExC_rxi->data,
-              sizeof(*RExC_rxi->data) + sizeof(void*) * (count + n - 1),
-              char, struct reg_data);
+    U32 count = RExC_rxi->data ? RExC_rxi->data->count : 0;
+
+    Renewc(RExC_rxi->data,
+          sizeof(*RExC_rxi->data) + sizeof(void*) * (count + n - 1),
+          char, struct reg_data);
+    if(count)
        Renew(RExC_rxi->data->what, count + n, U8);
-       RExC_rxi->data->count += n;
-    }
-    else {
-       Newxc(RExC_rxi->data, sizeof(*RExC_rxi->data) + sizeof(void*) * (n - 1),
-            char, struct reg_data);
+    else
        Newx(RExC_rxi->data->what, n, U8);
-       RExC_rxi->data->count = n;
-    }
-    Copy(s, RExC_rxi->data->what + RExC_rxi->data->count - n, n, U8);
-    return RExC_rxi->data->count - n;
+    RExC_rxi->data->count = count + n;
+    Copy(s, RExC_rxi->data->what + count, n, U8);
+    return count;
 }
 
 #ifndef PERL_IN_XSUB_RE