Common: Merge CRC32.h into Hash.h

This makes it easier to find the relevant functions.
This commit is contained in:
Pokechu22 2021-12-10 12:47:03 -08:00
parent 85d2ea0dd2
commit 2652aed85c
7 changed files with 16 additions and 35 deletions

View file

@ -25,8 +25,6 @@ add_library(common
Config/Layer.cpp
Config/Layer.h
CPUDetect.h
CRC32.cpp
CRC32.h
Crypto/AES.cpp
Crypto/AES.h
Crypto/bn.cpp

View file

@ -1,19 +0,0 @@
// Copyright 2021 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Common/CRC32.h"
#include <zlib.h>
namespace Common
{
u32 ComputeCRC32(std::string_view data)
{
const Bytef* buf = reinterpret_cast<const Bytef*>(data.data());
uInt len = static_cast<uInt>(data.size());
// Use zlibs crc32 implementation to compute the hash
u32 hash = crc32(0L, Z_NULL, 0);
hash = crc32(hash, buf, len);
return hash;
}
} // namespace Common

View file

@ -1,11 +0,0 @@
// Copyright 2021 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <string_view>
#include "Common/CommonTypes.h"
namespace Common
{
u32 ComputeCRC32(std::string_view data);
} // namespace Common

View file

@ -5,6 +5,8 @@
#include <algorithm>
#include <cstring>
#include <zlib.h>
#include "Common/BitUtils.h"
#include "Common/CPUDetect.h"
#include "Common/CommonFuncs.h"
@ -529,4 +531,14 @@ void SetHash64Function()
ptrHashFunction = &GetMurmurHash3;
}
}
u32 ComputeCRC32(std::string_view data)
{
const Bytef* buf = reinterpret_cast<const Bytef*>(data.data());
uInt len = static_cast<uInt>(data.size());
// Use zlib's crc32 implementation to compute the hash
u32 hash = crc32(0L, Z_NULL, 0);
hash = crc32(hash, buf, len);
return hash;
}
} // namespace Common

View file

@ -4,6 +4,7 @@
#pragma once
#include <cstddef>
#include <string_view>
#include "Common/CommonTypes.h"
@ -14,4 +15,6 @@ u32 HashAdler32(const u8* data, size_t len); // Fairly accurate, slightl
u32 HashEctor(const u8* ptr, size_t length); // JUNK. DO NOT USE FOR NEW THINGS
u64 GetHash64(const u8* src, u32 len, u32 samples);
void SetHash64Function();
u32 ComputeCRC32(std::string_view data);
} // namespace Common

View file

@ -22,11 +22,11 @@ namespace fs = std::filesystem;
#include "Common/Align.h"
#include "Common/CDUtils.h"
#include "Common/CRC32.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
#include "Common/FileUtil.h"
#include "Common/Hash.h"
#include "Common/IOFile.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"

View file

@ -21,7 +21,6 @@
<ClInclude Include="Common\BitUtils.h" />
<ClInclude Include="Common\BlockingLoop.h" />
<ClInclude Include="Common\CDUtils.h" />
<ClInclude Include="Common\CRC32.h" />
<ClInclude Include="Common\ChunkFile.h" />
<ClInclude Include="Common\CodeBlock.h" />
<ClInclude Include="Common\ColorUtil.h" />
@ -687,7 +686,6 @@
<ClCompile Include="AudioCommon\WaveFile.cpp" />
<ClCompile Include="Common\Analytics.cpp" />
<ClCompile Include="Common\CDUtils.cpp" />
<ClCompile Include="Common\CRC32.cpp" />
<ClCompile Include="Common\ColorUtil.cpp" />
<ClCompile Include="Common\CommonFuncs.cpp" />
<ClCompile Include="Common\CompatPatches.cpp" />