summaryrefslogtreecommitdiff
path: root/regcomp.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-11-26 18:44:57 +0000
committerNicholas Clark <nick@ccl4.org>2006-11-26 18:44:57 +0000
commit4a4e7719d3ad3a7cd7b1504c2ab39dd9db11de1f (patch)
treed61605021814a2203e8268aab9373b1708aadf25 /regcomp.c
parent2eccd3b2550197fc30b4f217fbedb861d6732099 (diff)
downloadperl-4a4e7719d3ad3a7cd7b1504c2ab39dd9db11de1f.tar.gz
Simplify S_add_data(), given that realloc will NULL acts as malloc().
p4raw-id: //depot/perl@29387
Diffstat (limited to 'regcomp.c')
-rw-r--r--regcomp.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/regcomp.c b/regcomp.c
index 7297eb63f1..320127c740 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