From e398812f15162cfea851ff0ba7efbdb2ea287ce1 Mon Sep 17 00:00:00 2001
From: Amelia Coutard <eliottulio.coutard@gmail.com>
Date: Sun, 19 Mar 2023 03:03:05 +0100
Subject: [PATCH] Simplified implementation of `allocate` a bit

---
 kernel/src/paging.cpp | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

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<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 };
 }
-- 
2.46.0