Skip to content

Commit beb595b

Browse files
committed
regcomp: reduce some code duplication
The tail of each branch is basically the same, so we can pull out the common code. Also, we don't need to SvIV() twice if we store the result of the first call in a local variable. Addresses #23364.
1 parent 8785c11 commit beb595b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

regcomp.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,26 +395,28 @@ Perl_reginitcolors(pTHX)
395395
regexp_engine const *
396396
Perl_current_re_engine(pTHX)
397397
{
398+
SV *ptr;
398399
if (IN_PERL_COMPILETIME) {
399400
HV * const table = GvHV(PL_hintgv);
400-
SV **ptr;
401+
SV **pptr;
401402

402403
if (!table || !(PL_hints & HINT_LOCALIZE_HH))
403404
return &PL_core_reg_engine;
404-
ptr = hv_fetchs(table, "regcomp", false);
405-
if ( !(ptr && SvIOK(*ptr) && SvIV(*ptr)))
405+
pptr = hv_fetchs(table, "regcomp", false);
406+
if (!pptr)
406407
return &PL_core_reg_engine;
407-
return INT2PTR(regexp_engine*, SvIV(*ptr));
408+
ptr = *pptr;
408409
}
409410
else {
410-
SV *ptr;
411411
if (!PL_curcop->cop_hints_hash)
412412
return &PL_core_reg_engine;
413413
ptr = cop_hints_fetch_pvs(PL_curcop, "regcomp", 0);
414-
if ( !(ptr && SvIOK(ptr) && SvIV(ptr)))
415-
return &PL_core_reg_engine;
416-
return INT2PTR(regexp_engine*, SvIV(ptr));
417414
}
415+
416+
IV iv;
417+
if ( !(ptr && SvIOK(ptr) && (iv = SvIV(ptr))) )
418+
return &PL_core_reg_engine;
419+
return INT2PTR(regexp_engine*, iv);
418420
}
419421

420422

0 commit comments

Comments
 (0)