]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Simplified implementation of `allocate` a bit
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Sun, 19 Mar 2023 02:03:05 +0000 (03:03 +0100)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Sun, 19 Mar 2023 02:03:05 +0000 (03:03 +0100)
kernel/src/paging.cpp

index 610a5e9ac190051e9b9da721f98f0c27a5ce00a8..b37bcba460cc0c42f3f5be90c564ff716a640b0f 100644 (file)
@@ -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<paging::page>(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<paging::page>(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<paging::page>(it.get_phys_addr()),
+                       .size = count,
+               };
        }
        return { .ptr = nullptr, .size = count };
 }