diff options
| author | JosJuice <josjuice@gmail.com> | 2017-08-01 19:04:33 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2017-08-01 21:57:48 +0200 |
| commit | 1b1a75ee3ad52db3fca36158dca318376ebd0bb0 (patch) | |
| tree | 0b68dd50e4658ef199ffeea8f2d1c852467a70e3 /Source | |
| parent | d6260e02ce5561a614fc051c7340fe6c803399cd (diff) | |
DirectoryBlob: Lookup DiscContents by offset + size instead of offset
This simplifies DiscContentContainer::Read.
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/DiscIO/DirectoryBlob.cpp | 12 | ||||
| -rw-r--r-- | Source/Core/DiscIO/DirectoryBlob.h | 5 |
2 files changed, 9 insertions, 8 deletions
diff --git a/Source/Core/DiscIO/DirectoryBlob.cpp b/Source/Core/DiscIO/DirectoryBlob.cpp index e017bfca78..320d3ed054 100644 --- a/Source/Core/DiscIO/DirectoryBlob.cpp +++ b/Source/Core/DiscIO/DirectoryBlob.cpp @@ -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); diff --git a/Source/Core/DiscIO/DirectoryBlob.h b/Source/Core/DiscIO/DirectoryBlob.h index 86787bbd44..4c9646ac8f 100644 --- a/Source/Core/DiscIO/DirectoryBlob.h +++ b/Source/Core/DiscIO/DirectoryBlob.h @@ -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); } |
