Skip to content

Commit 023776e

Browse files
committed
fix: make CCache smaller
1 parent a0b659e commit 023776e

1 file changed

Lines changed: 12 additions & 34 deletions

File tree

include/dynlibutils/module.hpp

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -276,46 +276,24 @@ inline auto ParsePattern(const std::string_view svInput)
276276
struct CCache
277277
{
278278
std::string m_svPattern;
279-
uintptr_t m_nStart;
280-
uintptr_t m_pSectionAddr;
281-
size_t m_nSectionSize;
282-
283-
CCache(std::string_view svName, uintptr_t nMeta = 0)
284-
: m_svPattern(svName)
285-
, m_nStart(nMeta)
286-
, m_pSectionAddr(0)
287-
, m_nSectionSize(0) {
288-
}
279+
std::uintptr_t m_nStart = 0;
280+
std::uintptr_t m_pSectionAddr = 0;
281+
std::size_t m_nSectionSize = 0;
289282

290-
CCache(
291-
const volatile std::uint8_t* pPatternMem,
292-
const size_t nSize,
293-
const CMemory pStartAddress = nullptr,
294-
const Section_t* pModuleSection = nullptr
295-
)
296-
: m_svPattern(pPatternMem, pPatternMem + nSize)
297-
, m_nStart(pStartAddress.GetAddr())
298-
, m_pSectionAddr(pModuleSection ? pModuleSection->GetAddr() : 0)
299-
, m_nSectionSize(pModuleSection ? pModuleSection->m_nSectionSize : 0) {
300-
}
283+
CCache(std::string_view svPattern, const CMemory pStartAddress = nullptr, const Section_t* pModuleSection = nullptr)
284+
: m_svPattern(svPattern),
285+
m_nStart(pStartAddress.GetAddr()),
286+
m_pSectionAddr(pModuleSection ? pModuleSection->GetAddr() : 0),
287+
m_nSectionSize(pModuleSection ? pModuleSection->m_nSectionSize : 0) {}
301288

302-
bool operator==(const CCache& rhs) const noexcept
289+
[[nodiscard]] bool operator==(const CCache& rhs) const noexcept
303290
{
304-
return m_svPattern == rhs.m_svPattern &&
305-
m_nStart == rhs.m_nStart &&
306-
m_pSectionAddr == rhs.m_pSectionAddr &&
307-
m_nSectionSize == rhs.m_nSectionSize;
291+
return std::tie(m_svPattern, m_nStart, m_pSectionAddr, m_nSectionSize) == std::tie(rhs.m_svPattern, rhs.m_nStart, rhs.m_pSectionAddr, rhs.m_nSectionSize);
308292
}
309293

310-
bool operator<(const CCache& rhs) const noexcept
294+
[[nodiscard]] bool operator<(const CCache& rhs) const noexcept
311295
{
312-
if (m_svPattern != rhs.m_svPattern)
313-
return m_svPattern < rhs.m_svPattern;
314-
if (m_nStart != rhs.m_nStart)
315-
return m_nStart < rhs.m_nStart;
316-
if (m_pSectionAddr != rhs.m_pSectionAddr)
317-
return m_pSectionAddr < rhs.m_pSectionAddr;
318-
return m_nSectionSize < rhs.m_nSectionSize;
296+
return std::tie(m_svPattern, m_nStart, m_pSectionAddr, m_nSectionSize) < std::tie(rhs.m_svPattern, rhs.m_nStart, rhs.m_pSectionAddr, rhs.m_nSectionSize);
319297
}
320298
};
321299

0 commit comments

Comments
 (0)