| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Cc: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
| Subject: | One more bit of PL/Perl cleanup |
| Date: | 2026-08-19 20:40:42 |
| Message-ID: | 2034677.1787172042@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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 the first part of these tests is
pointless. I find in the Perl sources (sv.h):
#define SVf_IOK 0x00000100 /* has valid public integer value */
#define SVf_NOK 0x00000200 /* has valid public numeric value */
#define SVf_POK 0x00000400 /* has valid public pointer value */
#define SVf_ROK 0x00000800 /* has a valid reference pointer */
...
#define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
SVp_IOK|SVp_NOK|SVp_POK|SVpgv_GP)
...
#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
...
#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
SvOK() is evidently intended to encode "has a defined value of any
type" while SvROK() specifically means "has a reference value".
So I think we can make our code more idiomatic and (doubtless
not measurably) faster as attached.
regards, tom lane
| Attachment | Content-Type | Size |
|---|---|---|
| v1-remove-redundant-SvOK-tests.patch | text/x-diff | 1.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrey Rachitskiy | 2026-08-19 21:14:24 | Re: One more bit of PL/Perl cleanup |
| Previous Message | Tomas Vondra | 2026-08-19 20:32:19 | Re: hashjoins vs. Bloom filters (yet again) |