Skip to content

Commit c82f488

Browse files
committed
Allow custom PL_strtab hash in perl_construct.
Such a patch allow PL_strtab optimizations at compile time to statically malloc PL_strtab to an optimized size at startup. Custom entries can then be added (after PL_hash_seed initialization) without risking the hash to be reset by perl_construct.
1 parent a500027 commit c82f488

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

perl.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,20 @@ perl_construct(pTHXx)
371371
* constructing hashes */
372372
PL_hash_seed_set= TRUE;
373373
}
374-
/* Note that strtab is a rather special HV. Assumptions are made
375-
about not iterating on it, and not adding tie magic to it.
376-
It is properly deallocated in perl_destruct() */
377-
PL_strtab = newHV();
378-
379-
/* SHAREKEYS tells us that the hash has its keys shared with PL_strtab,
380-
* which is not the case with PL_strtab itself */
381-
HvSHAREKEYS_off(PL_strtab); /* mandatory */
382-
hv_ksplit(PL_strtab, 1 << 11);
374+
375+
/* Allow PL_strtab to be pre-initialized before calling perl_construct.
376+
* can use a custom optimized PL_strtab hash before calling perl_construct */
377+
if (!PL_strtab) {
378+
/* Note that strtab is a rather special HV. Assumptions are made
379+
about not iterating on it, and not adding tie magic to it.
380+
It is properly deallocated in perl_destruct() */
381+
PL_strtab = newHV();
382+
383+
/* SHAREKEYS tells us that the hash has its keys shared with PL_strtab,
384+
* which is not the case with PL_strtab itself */
385+
HvSHAREKEYS_off(PL_strtab); /* mandatory */
386+
hv_ksplit(PL_strtab, 1 << 11);
387+
}
383388

384389
Zero(PL_sv_consts, SV_CONSTS_COUNT, SV*);
385390

0 commit comments

Comments
 (0)