summaryrefslogtreecommitdiff
path: root/regcomp.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2007-02-10 22:31:55 +0100
committerH.Merijn Brand <h.m.brand@xs4all.nl>2007-02-10 20:41:31 +0000
commit76a476f9104f7947fe0fedc97cbf22a34bfffa87 (patch)
tree17bd0b823e903f0675eb79bf965fd711e593e0f9 /regcomp.c
parenta1216aced59ab8ef16c7c3220a50dad6ed434ef2 (diff)
downloadperl-76a476f9104f7947fe0fedc97cbf22a34bfffa87.tar.gz
Re: [NL-PM] Fw: [PATCH - provisional] H. Merijn Brands idea of buffer numbering.
Message-ID: <9b18b3110702101231j5e91cc20g780a8c581af02dd5@mail.gmail.com> p4raw-id: //depot/perl@30200
Diffstat (limited to 'regcomp.c')
-rw-r--r--regcomp.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/regcomp.c b/regcomp.c
index c526c3a6e2..5f1efdc015 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -5168,11 +5168,26 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth)
Perl_croak(aTHX_
"panic: paren_name hash element allocation failed");
} else if ( SvPOK(sv_dat) ) {
- IV count=SvIV(sv_dat);
- I32 *pv=(I32*)SvGROW(sv_dat,SvCUR(sv_dat)+sizeof(I32)+1);
- SvCUR_set(sv_dat,SvCUR(sv_dat)+sizeof(I32));
- pv[count]=RExC_npar;
- SvIVX(sv_dat)++;
+ /* (?|...) can mean we have dupes so scan to check
+ its already been stored. Maybe a flag indicating
+ we are inside such a construct would be useful,
+ but the arrays are likely to be quite small, so
+ for now we punt -- dmq */
+ IV count = SvIV(sv_dat);
+ I32 *pv = (I32*)SvPVX(sv_dat);
+ IV i;
+ for ( i = 0 ; i < count ; i++ ) {
+ if ( pv[i] == RExC_npar ) {
+ count = 0;
+ break;
+ }
+ }
+ if ( count ) {
+ pv = (I32*)SvGROW(sv_dat, SvCUR(sv_dat) + sizeof(I32)+1);
+ SvCUR_set(sv_dat, SvCUR(sv_dat) + sizeof(I32));
+ pv[count] = RExC_npar;
+ SvIVX(sv_dat)++;
+ }
} else {
(void)SvUPGRADE(sv_dat,SVt_PVNV);
sv_setpvn(sv_dat, (char *)&(RExC_npar), sizeof(I32));