Re: Efficient HV fetches without recomputing the key hash
[email protected] (Aristotle Pagaltzis via perl5-porters) Thu, 14 May 2026 09:33:13 +0200
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
* Paul "LeoNerd" Evans <[email protected]> [2026-05-13 19:58]: > * Directly reach-around the `hv_fetch*` macros by observing that > they are all just wrappers around hv_common(), and make myself a > brand new wrapper, something like > > #define hv_fetch_with_hash(hv, key, klen, lval, hash) \ > hv_common_key_len((hv), (key), (klen), \ > (HV_FETCH_JUST_SV | ((lval) ? HV_FETCH_LVALUE : 0)), \ > NULL, (hash)) > > That's a straight-up copy of hv_fetch, just passing in (hash) > rather than 0 for the hash value. > > Downside: not guaranteed to continue to work in newer perls > > * Add a new API function with this shape, and then call it. > > SV **hv_fetch_with_hash(HV *hv, const char *key, I32 klen, > I32 lval, U32 hash); > > Downside: doesn't work on older perls. The nice thing about the past is that it’s not subject to change and already known. A polyfill of a new function for old perls is a finite, knowable, fixed amount of work. The future is not as nice. [yada Yada PPPort, as per everyone else]