From: Nicholas Clark Date: Sun, 26 Nov 2006 22:21:02 +0000 (+0000) Subject: Moving the reference count to the front of both _reg_trie_data and X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=23eab42ccdcdf01b414e4c1728d8f919b2705614;p=p5sagit%2Fp5-mst-13.2.git Moving the reference count to the front of both _reg_trie_data and _reg_ac_data allows smaller code in Perl_regdupe. p4raw-id: //depot/perl@29391 --- diff --git a/regcomp.c b/regcomp.c index bfcbd6b..5513a0a 100644 --- a/regcomp.c +++ b/regcomp.c @@ -8714,6 +8714,13 @@ Perl_regdupe(pTHX_ const regexp *r, CLONE_PARAMS *param) d->data[i] = (void*)OpREFCNT_inc((OP*)ri->data->data[i]); OP_REFCNT_UNLOCK; break; + case 'T': + /* Trie stclasses are readonly and can thus be shared + * without duplication. We free the stclass in pregfree + * when the corresponding reg_ac_data struct is freed. + */ + reti->regstclass= ri->regstclass; + /* Fall through */ case 't': OP_REFCNT_LOCK; ((reg_trie_data*)ri->data->data[i])->refcount++; @@ -8722,17 +8729,6 @@ Perl_regdupe(pTHX_ const regexp *r, CLONE_PARAMS *param) case 'n': d->data[i] = ri->data->data[i]; break; - case 'T': - d->data[i] = ri->data->data[i]; - OP_REFCNT_LOCK; - ((reg_ac_data*)d->data[i])->refcount++; - OP_REFCNT_UNLOCK; - /* Trie stclasses are readonly and can thus be shared - * without duplication. We free the stclass in pregfree - * when the corresponding reg_ac_data struct is freed. - */ - reti->regstclass= ri->regstclass; - break; default: Perl_croak(aTHX_ "panic: re_dup unknown data code '%c'", ri->data->what[i]); } diff --git a/regcomp.h b/regcomp.h index e8fd39f..f591726 100644 --- a/regcomp.h +++ b/regcomp.h @@ -512,8 +512,11 @@ typedef struct _reg_trie_trans reg_trie_trans; /* anything in here that needs to be freed later - should be dealt with in pregfree */ + should be dealt with in pregfree. + refcount is first in both this and _reg_ac_data to allow a space + optimisation in Perl_regdupe. */ struct _reg_trie_data { + U32 refcount; /* number of times this trie is referenced */ U16 uniquecharcount; /* unique chars in trie (width of trans table) */ U32 lasttrans; /* last valid transition element */ U16 *charmap; /* byte to charid lookup array */ @@ -521,7 +524,6 @@ struct _reg_trie_data { reg_trie_state *states; /* state data */ reg_trie_trans *trans; /* array of transition elements */ char *bitmap; /* stclass bitmap */ - U32 refcount; /* number of times this trie is referenced */ U32 startstate; /* initial state - used for common prefix optimisation */ STRLEN minlen; /* minimum length of words in trie - build/opt only? */ STRLEN maxlen; /* maximum length of words in trie - build/opt only? */ @@ -541,11 +543,13 @@ struct _reg_trie_data { }; typedef struct _reg_trie_data reg_trie_data; +/* refcount is first in both this and _reg_trie_data to allow a space + optimisation in Perl_regdupe. */ struct _reg_ac_data { + U32 refcount; U32 *fail; reg_trie_state *states; reg_trie_data *trie; - U32 refcount; }; typedef struct _reg_ac_data reg_ac_data;