Mailing List Archive

perl api: best way to look up one hash's HE* in another hash?
I'm trying to optimize some XS code where I iterate one hash and look
for its keys in a second hash.  The APIs in perlapi don't seem to line
up well for this task.

While iterating, the most efficient way seems to be hv_iternext, which
gives me an HE*.  My understanding is that the HE may contain the key as
1) a byte buffer, 2) a utf8 character buffer, or 3) a pointer to an SV*

When I go to the second hash to look this up, my options are hv_fetch
and hv_exists (which need the char buffer and positive/negative length
as a utf8 flag) or hv_exists_ent and hv_fetch_ent, which need an SV* and
hash code.  With the first pair, I can't specify the hash code, which
means it will get re-calculated unnecessarily since I already have it in
the HE*, and I don't see how to get the utf8 flag out of the existing
HE, which might become a unicode bug?  With the second pair, I can
specify the hash code but will often be allocating an unnecessary SV* if
the hash key was stored as a char buffer.

Since it seems like all of this is just a front-end to Perl_hv_common,
which accepts any/all arguments given the right flags, it seems like
there ought to be a public API that can optimally look up one hash's HE
in a second hash.  Am I missing something?

-Mike C.