From 0c19f895d39b3302488acf9b6006fb524fb0e4d6 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Fri, 10 Dec 2021 13:34:40 -0800 Subject: Replace remaining uses of zlib crc32 with Common/Hash.h --- Source/Core/Common/Hash.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'Source/Core/Common/Hash.cpp') 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(data.data()); - uInt len = static_cast(data.size()); + return ComputeCRC32(reinterpret_cast(data.data()), static_cast(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); + static_assert(std::is_same_v); // 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 -- cgit v1.2.3