DirectoryBlob: Lookup DiscContents by offset + size instead of offset

This simplifies DiscContentContainer::Read.
This commit is contained in:
JosJuice 2017-08-01 19:04:33 +02:00
parent d6260e02ce
commit 1b1a75ee3a
2 changed files with 9 additions and 8 deletions

View File

@ -77,6 +77,11 @@ u64 DiscContent::GetOffset() const
return m_offset;
}
u64 DiscContent::GetEndOffset() const
{
return m_offset + m_size;
}
u64 DiscContent::GetSize() const
{
return m_size;
@ -138,13 +143,8 @@ const DiscContent& DiscContentContainer::CheckSizeAndAdd(u64 offset, u64 max_siz
bool DiscContentContainer::Read(u64 offset, u64 length, u8* buffer) const
{
if (m_contents.empty())
return true;
// Determine which DiscContent the offset refers to
std::set<DiscContent>::const_iterator it = m_contents.lower_bound(DiscContent(offset));
if (it->GetOffset() > offset && it != m_contents.begin())
--it;
std::set<DiscContent>::const_iterator it = m_contents.upper_bound(DiscContent(offset));
// zero fill to start of file data
PadToAddress(it->GetOffset(), &offset, &length, &buffer);

View File

@ -42,12 +42,13 @@ public:
explicit DiscContent(u64 offset);
u64 GetOffset() const;
u64 GetEndOffset() const;
u64 GetSize() const;
bool Read(u64* offset, u64* length, u8** buffer) const;
bool operator==(const DiscContent& other) const { return m_offset == other.m_offset; }
bool operator==(const DiscContent& other) const { return GetEndOffset() == other.GetEndOffset(); }
bool operator!=(const DiscContent& other) const { return !(*this == other); }
bool operator<(const DiscContent& other) const { return m_offset < other.m_offset; }
bool operator<(const DiscContent& other) const { return GetEndOffset() < other.GetEndOffset(); }
bool operator>(const DiscContent& other) const { return other < *this; }
bool operator<=(const DiscContent& other) const { return !(*this < other); }
bool operator>=(const DiscContent& other) const { return !(*this > other); }