aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-21 23:32:05 +0100
committerDan Engelbrecht <[email protected]>2022-03-31 11:28:33 +0200
commite019bf65635cb863609af2457b0627625bd8bf8d (patch)
tree5e39b3c67890625d478913fea73ca33856cf80c7
parentreview feedback (diff)
downloadzen-e019bf65635cb863609af2457b0627625bd8bf8d.tar.xz
zen-e019bf65635cb863609af2457b0627625bd8bf8d.zip
Use less bit shifting and magic in CasDiskLocation
-rw-r--r--zenstore/compactcas.h27
1 files changed, 18 insertions, 9 deletions
diff --git a/zenstore/compactcas.h b/zenstore/compactcas.h
index 01cfffa52..f9e60aec8 100644
--- a/zenstore/compactcas.h
+++ b/zenstore/compactcas.h
@@ -49,8 +49,20 @@ struct CasDiskLocation
}
private:
- inline uint32_t BlockIndex() const { return (static_cast<uint32_t>(m_BlockIndexAndOffsetHighBits & 0xf) << 16) | m_BlockIndexLowBits; }
- inline uint64_t Offset() const { return (static_cast<uint64_t>(m_BlockIndexAndOffsetHighBits & 0xfff0) << 12) | m_OffsetLowBits; }
+ inline uint32_t BlockIndex() const
+ {
+ uint64_t PackedOffset = 0;
+ memcpy(&PackedOffset, &m_Offset, sizeof m_Offset);
+ return static_cast<std::uint32_t>(PackedOffset >> MaxOffsetBits);
+ }
+
+ inline uint64_t Offset() const
+ {
+ uint64_t PackedOffset = 0;
+ memcpy(&PackedOffset, &m_Offset, sizeof m_Offset);
+ return PackedOffset & MaxOffset;
+ }
+
inline uint64_t Size() const { return m_Size; }
inline void Init(uint32_t BlockIndex, uint64_t Offset, uint64_t Size)
@@ -59,16 +71,13 @@ private:
ZEN_ASSERT(Offset <= MaxOffset);
ZEN_ASSERT(Size <= std::numeric_limits<std::uint32_t>::max());
- m_Size = static_cast<uint32_t>(Size);
- m_BlockIndexLowBits = static_cast<uint16_t>(BlockIndex & 0xffff);
- m_OffsetLowBits = static_cast<uint16_t>(Offset & 0xffff);
- m_BlockIndexAndOffsetHighBits = static_cast<uint16_t>(((BlockIndex >> 16) & 0xf) | (((Offset >> 16) & 0xfff) << 4));
+ m_Size = static_cast<uint32_t>(Size);
+ uint64_t PackedOffset = (static_cast<uint64_t>(BlockIndex) << MaxOffsetBits) + Offset;
+ memcpy(&m_Offset[0], &PackedOffset, sizeof m_Offset);
}
uint32_t m_Size;
- uint16_t m_BlockIndexLowBits;
- uint16_t m_OffsetLowBits;
- uint16_t m_BlockIndexAndOffsetHighBits;
+ uint8_t m_Offset[6];
};
struct CasDiskIndexEntry