1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-10 06:01:52 +00:00

kern: optimize memory block tree lookups

This commit is contained in:
Michael Scire 2020-01-29 14:55:26 -08:00
parent 981bb1f15d
commit bb4ade30e4

View file

@ -123,12 +123,12 @@ namespace ams::kern {
u32 type_id; u32 type_id;
public: public:
static constexpr ALWAYS_INLINE int Compare(const KMemoryBlock &lhs, const KMemoryBlock &rhs) { static constexpr ALWAYS_INLINE int Compare(const KMemoryBlock &lhs, const KMemoryBlock &rhs) {
if (lhs.address < rhs.address) { if (lhs.GetAddress() < rhs.GetAddress()) {
return -1; return -1;
} else if (lhs.address == rhs.address) { } else if (lhs.GetLastAddress() > rhs.GetLastAddress()) {
return 0;
} else {
return 1; return 1;
} else {
return 0;
} }
} }
public: public:
@ -222,12 +222,11 @@ namespace ams::kern {
constexpr ALWAYS_INLINE KMemoryBlockTree() : tree() { /* ... */ } constexpr ALWAYS_INLINE KMemoryBlockTree() : tree() { /* ... */ }
public: public:
iterator FindContainingBlock(uintptr_t address) { iterator FindContainingBlock(uintptr_t address) {
for (auto it = this->begin(); it != this->end(); it++) { auto it = this->find(KMemoryBlock(address, 1, 0, 0));
if (it->Contains(address)) { MESOSPHERE_INIT_ABORT_UNLESS(it != this->end());
return it; MESOSPHERE_INIT_ABORT_UNLESS(it->Contains(address));
}
} return it;
MESOSPHERE_INIT_ABORT();
} }
iterator FindFirstBlockByTypeAttr(u32 type_id, u32 attr = 0) { iterator FindFirstBlockByTypeAttr(u32 type_id, u32 attr = 0) {