Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove class nesting #585

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions src/snmalloc/mem/sizeclasstable.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,40 +411,40 @@ namespace snmalloc
return (s - 1) >> MIN_ALLOC_BITS;
}

constexpr smallsizeclass_t size_to_sizeclass(size_t size)
constexpr size_t sizeclass_lookup_size =
sizeclass_lookup_index(MAX_SMALL_SIZECLASS_SIZE);

/**
* This struct is used to statically initialise a table for looking up
* the correct sizeclass.
*/
struct SizeClassLookup
{
constexpr size_t sizeclass_lookup_size =
sizeclass_lookup_index(MAX_SMALL_SIZECLASS_SIZE);
sizeclass_compress_t table[sizeclass_lookup_size] = {{}};

/**
* This struct is used to statically initialise a table for looking up
* the correct sizeclass.
*/
struct SizeClassLookup
constexpr SizeClassLookup()
{
sizeclass_compress_t table[sizeclass_lookup_size] = {{}};

constexpr SizeClassLookup()
size_t curr = 1;
for (sizeclass_compress_t sizeclass = 0;
sizeclass < NUM_SMALL_SIZECLASSES;
sizeclass++)
{
size_t curr = 1;
for (sizeclass_compress_t sizeclass = 0;
sizeclass < NUM_SMALL_SIZECLASSES;
sizeclass++)
for (; curr <= sizeclass_metadata.fast_small(sizeclass).size;
curr += 1 << MIN_ALLOC_BITS)
{
for (; curr <= sizeclass_metadata.fast_small(sizeclass).size;
curr += 1 << MIN_ALLOC_BITS)
{
auto i = sizeclass_lookup_index(curr);
if (i == sizeclass_lookup_size)
break;
table[i] = sizeclass;
}
auto i = sizeclass_lookup_index(curr);
if (i == sizeclass_lookup_size)
break;
table[i] = sizeclass;
}
}
};
}
};

constexpr SizeClassLookup sizeclass_lookup = SizeClassLookup();
constexpr SizeClassLookup sizeclass_lookup = SizeClassLookup();

constexpr smallsizeclass_t size_to_sizeclass(size_t size)
{
auto index = sizeclass_lookup_index(size);
if (index < sizeclass_lookup_size)
{
Expand Down