mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-02-01 20:32:48 +00:00
kern: optimize memory block tree lookups
This commit is contained in:
parent
981bb1f15d
commit
bb4ade30e4
1 changed files with 9 additions and 10 deletions
|
@ -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,13 +222,12 @@ 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());
|
||||||
|
MESOSPHERE_INIT_ABORT_UNLESS(it->Contains(address));
|
||||||
|
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
MESOSPHERE_INIT_ABORT();
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator FindFirstBlockByTypeAttr(u32 type_id, u32 attr = 0) {
|
iterator FindFirstBlockByTypeAttr(u32 type_id, u32 attr = 0) {
|
||||||
for (auto it = this->begin(); it != this->end(); it++) {
|
for (auto it = this->begin(); it != this->end(); it++) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue