From 1b1a75ee3ad52db3fca36158dca318376ebd0bb0 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 1 Aug 2017 19:04:33 +0200 Subject: [PATCH] DirectoryBlob: Lookup DiscContents by offset + size instead of offset This simplifies DiscContentContainer::Read. --- Source/Core/DiscIO/DirectoryBlob.cpp | 12 ++++++------ 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::const_iterator it = m_contents.lower_bound(DiscContent(offset)); - if (it->GetOffset() > offset && it != m_contents.begin()) - --it; + std::set::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); }