diff options
| author | Pokechu22 <Pokechu022@gmail.com> | 2021-12-10 13:34:40 -0800 |
|---|---|---|
| committer | Pokechu22 <Pokechu022@gmail.com> | 2022-01-01 10:36:38 -0800 |
| commit | 0c19f895d39b3302488acf9b6006fb524fb0e4d6 (patch) | |
| tree | 8e2981a8ad07c4a97535516c6a1111823f3c0c92 /Source/Core/Common | |
| parent | 2652aed85c0ab0ee9d51cfd5065b4bb4a620ab45 (diff) | |
Replace remaining uses of zlib crc32 with Common/Hash.h
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/Hash.cpp | 24 | ||||
| -rw-r--r-- | Source/Core/Common/Hash.h | 3 |
2 files changed, 22 insertions, 5 deletions
diff --git a/Source/Core/Common/Hash.cpp b/Source/Core/Common/Hash.cpp index 692745cb0a..62b56bc82c 100644 --- a/Source/Core/Common/Hash.cpp +++ b/Source/Core/Common/Hash.cpp @@ -534,11 +534,25 @@ void SetHash64Function() u32 ComputeCRC32(std::string_view data) { - const Bytef* buf = reinterpret_cast<const Bytef*>(data.data()); - uInt len = static_cast<uInt>(data.size()); + return ComputeCRC32(reinterpret_cast<const u8*>(data.data()), static_cast<u32>(data.size())); +} + +u32 ComputeCRC32(const u8* ptr, u32 length) +{ + return UpdateCRC32(StartCRC32(), ptr, length); +} + +u32 StartCRC32() +{ + return crc32(0L, Z_NULL, 0); +} + +u32 UpdateCRC32(u32 crc, const u8* ptr, u32 length) +{ + static_assert(std::is_same_v<const u8*, const Bytef*>); + static_assert(std::is_same_v<u32, uInt>); // Use zlib's crc32 implementation to compute the hash - u32 hash = crc32(0L, Z_NULL, 0); - hash = crc32(hash, buf, len); - return hash; + // crc32_z (which takes a size_t) would be better, but it isn't available on Android + return crc32(crc, ptr, length); } } // namespace Common diff --git a/Source/Core/Common/Hash.h b/Source/Core/Common/Hash.h index c346c343e4..c742ed0b64 100644 --- a/Source/Core/Common/Hash.h +++ b/Source/Core/Common/Hash.h @@ -17,4 +17,7 @@ u64 GetHash64(const u8* src, u32 len, u32 samples); void SetHash64Function(); u32 ComputeCRC32(std::string_view data); +u32 ComputeCRC32(const u8* ptr, u32 length); +u32 StartCRC32(); +u32 UpdateCRC32(u32 crc, const u8* ptr, u32 length); } // namespace Common |
