1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +00:00

LibC: Simplify malloc size classes

Problem:
- `size_classes` is a C-style array which makes it difficult to use in
  algorithms.
- `all_of` algorithm is re-written for the specific implementation.

Solution:
- Change `size_classes` to be an `Array`.
- Directly use the generic `all_of` algorithm instead of
  reimplementing.
This commit is contained in:
Lenny Maiorani 2021-05-17 15:17:06 -06:00 committed by Andreas Kling
parent c2ae6c189e
commit f91bcb8895
3 changed files with 12 additions and 18 deletions

View file

@ -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) * num_size_classes];
static u8 g_allocators_storage[sizeof(Allocator) * size_classes.size()];
static u8 g_big_allocators_storage[sizeof(BigAllocator)];
static inline Allocator (&allocators())[num_size_classes]
static inline Allocator (&allocators())[size_classes.size()]
{
return reinterpret_cast<Allocator(&)[num_size_classes]>(g_allocators_storage);
return reinterpret_cast<Allocator(&)[size_classes.size()]>(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 < num_size_classes; ++i) {
for (size_t i = 0; i < size_classes.size(); ++i) {
new (&allocators()[i]) Allocator();
allocators()[i].size = size_classes[i];
}