Commit bc910acb authored by Arthur O'Dwyer's avatar Arthur O'Dwyer
Browse files

Keeping it simple on the newly added macros (SADD, BY_HVAL)

This (#80) is just a PR to clean up the existing implementations, with no
API changes at all (except to stop exposing HASH_GHV_*, HASH_ADD_*LOGUE,
and HASH_SORTED_ADD to user code). The benefit is that with the code
simplified, it's easier to see how each function is meant to behave and
to see which ones are "convenience wrappers" for more primitive functions.

* Inline the HASH_GHV_ "helpers".
* Normalize parenthesization of macro arguments.

The rule is "parenthesize all your own arguments, for sanity."
If you're calling another function or macro, you don't need to
parenthesize *their* arguments, because they'll do it. Also,
because your own arguments can't contain unbraced commas, it's
safe to call e.g. `f(a,b)` where `a,b` are your own arguments.
However, it's never safe to use `a->b` without parenthesizing
it: `(a)->b`.

The one intentional exception here is `cmpfcn`, which is allowed
to be a macro name. Invoking `(cmpfcn)(a,b)` would be incorrect
because it would suppress the intended macro expansion of `cmpfcn(a,b)`.

* Inline the "helper" macro HASH_ADD_EPILOGUE.
* Inline the "helper" macro HASH_ADD_PROLOGUE.
* Inline the "helper" macro HASH_SORTED_ADD.
* Remove redundancy among the various HASH_[S]ADD macros.

For the ones that don't know the hashvalue to start with,
the algorithm is "compute the hashvalue, then delegate to the
hashvalue-based ones." You can't do better than that, and as
a bonus, we end up dereferencing fewer pointers because this
way the hashvalue is always cached in a local variable.

* Remove redundancy between HASH_FIND and HASH_FIND_BY_HVAL.
parent 1d7cb683
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment