From 41868e8aaa6cfff63b1c8010e1356e01d86a1326 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 20 Aug 2026 11:26:11 -0400 Subject: [PATCH] Remove redundant SvOK() tests in plperl. I noticed that some places in our code test "SvOK(sv) && SvROK(sv)" while others check just SvROK(sv). On investigation, it's clear that SvROK implies SvOK so testing both is pointless. While removing these extra checks seems very unlikely to make any performance difference, it does make the code more consistent and intelligible. Also mop up a couple of places where there wasn't a null-pointer check before a SvOK() test. I think these are unreachable cases, but in the name of consistency let's do it the same everywhere. Author: Tom Lane Reviewed-by: Andrey Rachitskiy Discussion: https://postgr.es/m/2034677.1787172042@sss.pgh.pa.us --- src/pl/plperl/plperl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index ace39cd072b..a59dbc94372 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1095,7 +1095,7 @@ get_perl_array_ref(SV *sv) { dTHX; - if (sv && SvOK(sv) && SvROK(sv)) + if (sv && SvROK(sv)) { if (SvTYPE(SvRV(sv)) == SVt_PVAV) return sv; @@ -1107,8 +1107,7 @@ get_perl_array_ref(SV *sv) if (sav && *sav) { plperl_materialize_sv(*sav); - if (SvOK(*sav) && SvROK(*sav) && - SvTYPE(SvRV(*sav)) == SVt_PVAV) + if (SvROK(*sav) && SvTYPE(SvRV(*sav)) == SVt_PVAV) return *sav; } @@ -1767,7 +1766,7 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup) (errcode(ERRCODE_UNDEFINED_COLUMN), errmsg("$_TD->{new} does not exist"))); plperl_materialize_sv(*svp); - if (!SvOK(*svp) || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) + if (!(*svp) || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("$_TD->{new} is not a hash reference"))); @@ -2469,7 +2468,7 @@ plperl_func_handler(PG_FUNCTION_ARGS) plperl_return_next_internal(*svp); } } - else if (SvOK(perlret)) + else if (perlret && SvOK(perlret)) { ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), @@ -3357,7 +3356,7 @@ plperl_return_next_internal(SV *sv) HeapTuple tuple; plperl_materialize_sv(sv); - if (!(SvOK(sv) && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV)) + if (!(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("SETOF-composite-returning PL/Perl function "