Index: src/OFMapTable.m ================================================================== --- src/OFMapTable.m +++ src/OFMapTable.m @@ -25,10 +25,12 @@ #import "OFEnumerator.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" + +extern unsigned long OFHashSeed; static const unsigned long minCapacity = 16; struct OFMapTableBucket { void *key, *object; Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -281,10 +281,60 @@ if (!OFSizeEqual(rect1.size, rect2.size)) return false; return true; } + +/** + * @brief Adds the specified byte to the hash. + * + * @param hash A pointer to a hash to add the byte to + * @param byte The byte to add to the hash + */ +static OF_INLINE void +OFHashAdd(unsigned long *_Nonnull hash, unsigned char byte) +{ + uint32_t tmp = (uint32_t)*hash; + + tmp += byte; + tmp += tmp << 10; + tmp ^= tmp >> 6; + + *hash = tmp; +} + +/** + * @brief Adds the specified hash to the hash. + * + * @param hash A pointer to a hash to add the hash to + * @param otherHash The hash to add to the hash + */ +static OF_INLINE void +OFHashAddHash(unsigned long *_Nonnull hash, unsigned long otherHash) +{ + OFHashAdd(hash, (otherHash >> 24) & 0xFF); + OFHashAdd(hash, (otherHash >> 16) & 0xFF); + OFHashAdd(hash, (otherHash >> 8) & 0xFF); + OFHashAdd(hash, otherHash & 0xFF); +} + +/** + * @brief Finalizes the specified hash. + * + * @param hash A pointer to the hash to finalize + */ +static OF_INLINE void +OFHashFinalize(unsigned long *_Nonnull hash) +{ + uint32_t tmp = (uint32_t)*hash; + + tmp += tmp << 3; + tmp ^= tmp >> 11; + tmp += tmp << 15; + + *hash = tmp; +} static const size_t OFNotFound = SIZE_MAX; #ifdef __OBJC__ @class OFMethodSignature; @@ -1330,10 +1380,17 @@ * @brief Returns 64 bit or non-cryptographical randomness. * * @return 64 bit or non-cryptographical randomness */ extern uint64_t OFRandom64(void); + +/** + * @brief Initializes the specified hash. + * + * @param hash A pointer to the hash to initialize + */ +extern void OFHashInit(unsigned long *_Nonnull hash); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -225,10 +225,16 @@ return buffer; #else return ((uint64_t)OFRandom32() << 32) | OFRandom32(); #endif } + +void +OFHashInit(unsigned long *hash) +{ + *hash = OFHashSeed; +} static const char * typeEncodingForSelector(Class class, SEL selector) { Method method; Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -637,51 +637,10 @@ : (value)) #define OFRoundUpToPowerOf2(pow2, value) \ (((value) + (pow2) - 1) & ~((pow2) - 1)) -extern unsigned long OFHashSeed; - -static OF_INLINE void -OFHashInit(unsigned long *_Nonnull hash) -{ - *hash = OFHashSeed; -} - -static OF_INLINE void -OFHashAdd(unsigned long *_Nonnull hash, unsigned char byte) -{ - uint32_t tmp = (uint32_t)*hash; - - tmp += byte; - tmp += tmp << 10; - tmp ^= tmp >> 6; - - *hash = tmp; -} - -static OF_INLINE void -OFHashAddHash(unsigned long *_Nonnull hash, unsigned long otherHash) -{ - OFHashAdd(hash, (otherHash >> 24) & 0xFF); - OFHashAdd(hash, (otherHash >> 16) & 0xFF); - OFHashAdd(hash, (otherHash >> 8) & 0xFF); - OFHashAdd(hash, otherHash & 0xFF); -} - -static OF_INLINE void -OFHashFinalize(unsigned long *_Nonnull hash) -{ - uint32_t tmp = (uint32_t)*hash; - - tmp += tmp << 3; - tmp ^= tmp >> 11; - tmp += tmp << 15; - - *hash = tmp; -} - static OF_INLINE bool OFBitsetIsSet(unsigned char *_Nonnull storage, size_t idx) { return storage[idx / CHAR_BIT] & (1u << (idx % CHAR_BIT)); } Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -48,10 +48,12 @@ /* Newer versions of libctru started using id as a parameter name. */ # define id id_3ds # include <3ds.h> # undef id #endif + +extern unsigned long OFHashSeed; #ifdef OF_PSP static int exit_cb(int arg1, int arg2, void *arg) {