summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorJohn Naylor2024-04-06 05:17:07 +0000
committerJohn Naylor2024-04-06 05:20:40 +0000
commitf956ecd0353b2960f8322b2211142113fe2b6f67 (patch)
tree19ba604fb7f7cf34f3fcfbb4349810cb26a29030 /src/include
parentdb17594ad73a871a176a9bf96e0589c2cf57052c (diff)
Convert uses of hash_string_pointer to fasthash equivalent
Remove duplicate hash_string_pointer() function definitions by creating a new inline function hash_string() for this purpose. This has the added advantage of avoiding strlen() calls when doing hash lookup. It's not clear how many of these are perfomance-sensitive enough to benefit from that, but the simplification is worth it on its own. Reviewed by Jeff Davis Discussion: https://postgr.es/m/CANWCAZbg_XeSeY0a_PqWmWqeRATvzTzUNYRLeT%2Bbzs%2BYQdC92g%40mail.gmail.com
Diffstat (limited to 'src/include')
-rw-r--r--src/include/common/hashfn_unstable.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/include/common/hashfn_unstable.h b/src/include/common/hashfn_unstable.h
index d7ab6eeefe7..c93c9d71792 100644
--- a/src/include/common/hashfn_unstable.h
+++ b/src/include/common/hashfn_unstable.h
@@ -370,4 +370,24 @@ fasthash32(const char *k, size_t len, uint64 seed)
return fasthash_reduce32(fasthash64(k, len, seed));
}
+/*
+ * Convenience function for hashing NUL-terminated strings
+ */
+static inline uint32
+hash_string(const char *s)
+{
+ fasthash_state hs;
+ size_t s_len;
+
+ fasthash_init(&hs, 0);
+
+ /*
+ * Combine string into the hash and save the length for tweaking the final
+ * mix.
+ */
+ s_len = fasthash_accum_cstring(&hs, s);
+
+ return fasthash_final32(&hs, s_len);
+}
+
#endif /* HASHFN_UNSTABLE_H */