summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-05-18 08:32:05 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-18 08:32:05 +0200
commit7957f13e98655082456eb5b2b6996a2fecb1461f (patch)
tree6d72bcb6f0dfa2cc86f05a2c00f5de8714e36e6d /Userland/Libraries/LibC
parentf5c4d865923b5bab70830d7752e6cf7825872563 (diff)
downloadserenity-7957f13e98655082456eb5b2b6996a2fecb1461f.zip
Revert "LibC: Simplify malloc size classes"
This reverts commit f91bcb8895cd6b76b2977ad0632fef521ba2f1d1.
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/malloc.cpp8
-rw-r--r--Userland/Libraries/LibC/mallocdefs.h18
2 files changed, 16 insertions, 10 deletions
diff --git a/Userland/Libraries/LibC/malloc.cpp b/Userland/Libraries/LibC/malloc.cpp
index 1da5b43ad9..43519cf296 100644
--- a/Userland/Libraries/LibC/malloc.cpp
+++ b/Userland/Libraries/LibC/malloc.cpp
@@ -102,12 +102,12 @@ struct BigAllocator {
// are run. Similarly, we can not allow global destructors to destruct
// them. We could have used AK::NeverDestoyed to prevent the latter,
// but it would have not helped with the former.
-static u8 g_allocators_storage[sizeof(Allocator) * size_classes.size()];
+static u8 g_allocators_storage[sizeof(Allocator) * num_size_classes];
static u8 g_big_allocators_storage[sizeof(BigAllocator)];
-static inline Allocator (&allocators())[size_classes.size()]
+static inline Allocator (&allocators())[num_size_classes]
{
- return reinterpret_cast<Allocator(&)[size_classes.size()]>(g_allocators_storage);
+ return reinterpret_cast<Allocator(&)[num_size_classes]>(g_allocators_storage);
}
static inline BigAllocator (&big_allocators())[1]
@@ -442,7 +442,7 @@ void __malloc_init()
if (secure_getenv("LIBC_PROFILE_MALLOC"))
s_profiling = true;
- for (size_t i = 0; i < size_classes.size(); ++i) {
+ for (size_t i = 0; i < num_size_classes; ++i) {
new (&allocators()[i]) Allocator();
allocators()[i].size = size_classes[i];
}
diff --git a/Userland/Libraries/LibC/mallocdefs.h b/Userland/Libraries/LibC/mallocdefs.h
index 4237219260..ebf90eeaef 100644
--- a/Userland/Libraries/LibC/mallocdefs.h
+++ b/Userland/Libraries/LibC/mallocdefs.h
@@ -6,8 +6,6 @@
#pragma once
-#include <AK/AllOf.h>
-#include <AK/Array.h>
#include <AK/InlineLinkedList.h>
#include <AK/Types.h>
@@ -16,10 +14,18 @@
#define MALLOC_SCRUB_BYTE 0xdc
#define FREE_SCRUB_BYTE 0xed
-static constexpr Array<unsigned short, 13> size_classes { 8, 16, 32, 64, 128, 256, 504, 1016, 2032, 4088, 8184, 16376, 32752 };
-static constexpr auto malloc_alignment = 8;
-static_assert(all_of(size_classes.begin(), size_classes.end(),
- [](const auto val) { return val % malloc_alignment == 0; }));
+static constexpr unsigned short size_classes[] = { 8, 16, 32, 64, 128, 256, 504, 1016, 2032, 4088, 8184, 16376, 32752, 0 };
+static constexpr size_t num_size_classes = (sizeof(size_classes) / sizeof(unsigned short)) - 1;
+
+consteval bool check_size_classes_alignment()
+{
+ for (size_t i = 0; i < num_size_classes; i++) {
+ if ((size_classes[i] % 8) != 0)
+ return false;
+ }
+ return true;
+}
+static_assert(check_size_classes_alignment());
struct CommonHeader {
size_t m_magic;