From: Amelia Coutard Date: Sun, 19 Mar 2023 02:03:05 +0000 (+0100) Subject: Simplified implementation of `allocate` a bit X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=e398812f15162cfea851ff0ba7efbdb2ea287ce1;p=voyage-au-centre-des-fichiers.git Simplified implementation of `allocate` a bit --- diff --git a/kernel/src/paging.cpp b/kernel/src/paging.cpp index 610a5e9..b37bcba 100644 --- a/kernel/src/paging.cpp +++ b/kernel/src/paging.cpp @@ -121,21 +121,18 @@ void os::paging::page_allocator_t::print_all() const { os::paging::page_allocator_t::block os::paging::page_allocator_t::allocate(std::uint64_t count) { for (auto it = begin(); it != end(); it = it->next) { - if (count == it->size) { - erase(it); - memset((void*)it, 0, count * 0x1000); - return { - .ptr = phys_ptr(it.get_phys_addr()), - .size = count, - }; - } else if (count < it->size) { - erase(split_at_offset(it, count)); - memset((void*)it, 0, count * 0x1000); - return { - .ptr = phys_ptr(it.get_phys_addr()), - .size = count, - }; + if (it->size < count) { + continue; + } + if (count < it->size) { + split_at_offset(it, count); } + erase(it); + memset((void*)it, 0, count * 0x1000); + return { + .ptr = phys_ptr(it.get_phys_addr()), + .size = count, + }; } return { .ptr = nullptr, .size = count }; }