From f8fc90e7545202b3e8695ccb60a6d1b13ba3aa93 Mon Sep 17 00:00:00 2001 From: Nolan O'Brien Date: Thu, 31 Oct 2024 18:01:57 -0700 Subject: [PATCH] Modernize in preparation for move to Layer Zero (#47342) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47342 There are things we can do to modernize `FBHashKit` to make it ready for prime time, aka Layer Zero. * Consolidate down to a singular `meta_hash(...)` generic macro (supports all primitives for hashing) * Eliminate the unnecessary C++ * Deprecate legacy FB APIs * Make logic (and interfaces) explicit for 32 vs 64 bit inputs and 32 vs 64 bit outputs * Introduce robust unit tests * Have unit tests actually testable for 32-bit hashes ## Changelog [Internal][Change] Prep to move `FBXXHashUtils` Reviewed By: cipolleschi Differential Revision: D65245787 fbshipit-source-id: 311404068fd9df2a77d1ae4850b8a785466e73f0 --- .../react-native/React/I18n/FBXXHashUtils.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/react-native/React/I18n/FBXXHashUtils.h b/packages/react-native/React/I18n/FBXXHashUtils.h index abfa11a8c5f..791746c8494 100644 --- a/packages/react-native/React/I18n/FBXXHashUtils.h +++ b/packages/react-native/React/I18n/FBXXHashUtils.h @@ -27,10 +27,6 @@ NS_ASSUME_NONNULL_BEGIN -#ifdef __cplusplus -extern "C" { -#endif - /// magic constants :-) static const uint64_t PRIME1 = 11400714785074694791ULL; static const uint64_t PRIME2 = 14029467366897019727ULL; @@ -106,13 +102,18 @@ NS_INLINE uint64_t h32bytes(const char *p, uint64_t len, const uint64_t seed) return h32bytes_compute(p, len, seed + PRIME1 + PRIME2, seed + PRIME2, seed, seed - PRIME1); } +/* + Primary APIs + */ + +NS_INLINE uint64_t meta_xxhash64(const char *p, uint64_t len, uint64_t seed) +{ + return finalize((len >= 32 ? h32bytes(p, len, seed) : seed + PRIME5) + len, p + (len & ~0x1FULL), len & 0x1FULL); +} + NS_INLINE uint64_t FBxxHash64(const char *p, uint64_t len, uint64_t seed) { - return finalize((len >= 32 ? h32bytes(p, len, seed) : seed + PRIME5) + len, p + (len & ~0x1F), len & 0x1F); + return meta_xxhash64(p, len, seed); } -#ifdef __cplusplus -} -#endif - NS_ASSUME_NONNULL_END