From 29896bb0a409c7b70c82cda796e802539e8b189a Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Sat, 26 Oct 2024 03:25:36 +0300 Subject: [PATCH] memory: Refactor SwapPT class --- include/memory/swap_pt.hpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/include/memory/swap_pt.hpp b/include/memory/swap_pt.hpp index 83c93c3..e9c5974 100644 --- a/include/memory/swap_pt.hpp +++ b/include/memory/swap_pt.hpp @@ -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(); + } }; }