[core] Optimize fnv1_hash to avoid string allocations for static entities (#10529)

This commit is contained in:
J. Nick Koston authored and GitHub committed 2025-09-02 21:17:14 -05:00
1 parent e3fb9c2a78
commit 1a054299d4
4 files changed
+22 -8

No files matched your search

+6 -4
View File
@@ -142,11 +142,13 @@ uint16_t crc16be(const uint8_t *data, uint16_t len, uint16_t crc, uint16_t poly,
return refout ? (crc ^ 0xffff) : crc;
}
uint32_t fnv1_hash(const std::string &str) {
uint32_t fnv1_hash(const char *str) {
uint32_t hash = 2166136261UL;
for (char c : str) {
hash *= 16777619UL;
hash ^= c;
if (str) {
while (*str) {
hash *= 16777619UL;
hash ^= *str++;
}
}
return hash;
}