From: Nicholas Clark Date: Sun, 26 Nov 2006 18:44:57 +0000 (+0000) Subject: Simplify S_add_data(), given that realloc will NULL acts as malloc(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4a4e7719d3ad3a7cd7b1504c2ab39dd9db11de1f;p=p5sagit%2Fp5-mst-13.2.git Simplify S_add_data(), given that realloc will NULL acts as malloc(). p4raw-id: //depot/perl@29387 --- diff --git a/regcomp.c b/regcomp.c index 7297eb6..320127c 100644 --- 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