memory: Refactor SwapPT class

This commit is contained in:
EnderIce2 2024-10-26 03:25:36 +03:00
parent b6006e379d
commit 29896bb0a4
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -31,12 +31,19 @@ namespace Memory
private:
PageTable *Replace = nullptr;
PageTable *Restore = nullptr;
bool Ignore;
public:
SwapPT(PageTable *ReplaceWith,
PageTable *RestoreWith = nullptr)
: Replace(ReplaceWith)
SwapPT(auto ReplaceWith,
auto _RestoreWith = nullptr)
: Replace((PageTable *)ReplaceWith)
{
PageTable *RestoreWith = (PageTable *)_RestoreWith;
this->Ignore = Replace == RestoreWith;
if (this->Ignore)
return;
if (RestoreWith)
Restore = RestoreWith;
else
@ -45,7 +52,13 @@ namespace Memory
Replace->Update();
}
~SwapPT() { Restore->Update(); }
~SwapPT()
{
if (this->Ignore)
return;
Restore->Update();
}
};
}