Skip to content

Commit

Permalink
simplify dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingerZhu committed Dec 14, 2024
1 parent 6421f9a commit a322264
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/snmalloc/ds_core/concept.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace snmalloc
*/
template<typename, typename = void>
constexpr bool is_type_complete_v = false;

template<typename T>
constexpr bool is_type_complete_v<T, std::void_t<decltype(sizeof(T))>> = true;

Expand Down
42 changes: 23 additions & 19 deletions src/snmalloc/ds_core/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <array>
#include <atomic>
#include <cstddef>
#include <tuple>
#include <type_traits>

Expand Down Expand Up @@ -305,39 +306,42 @@ namespace snmalloc
#endif

/**
* Append a raw pointer or to the buffer as a hex string.
* Append a nullptr
*/
void append_raw_ptr(const void* ptr)
void append(std::nullptr_t)
{
append(static_cast<unsigned long long>(reinterpret_cast<uintptr_t>(ptr)));
// TODO: CHERI bits.
append("(nullptr)");
}

/**
* Append a pointer.
* Append a raw pointer to the buffer as a hex string.
*/
template<class T>
void append(const T* ptr)
void append(void* ptr)
{
if constexpr (std::is_same_v<T, char>)
if (ptr == nullptr)
{
while (char data = *ptr++)
{
append_char(data);
}
}
else
{
append_raw_ptr(ptr);
append(nullptr);
return;
}
append(static_cast<unsigned long long>(reinterpret_cast<uintptr_t>(ptr)));
// TODO: CHERI bits.
}

/**
* Append a null pointer.
* Append a literal pointer.
*/
void append(std::nullptr_t ptr)
void append(const char* ptr)
{
append_raw_ptr(ptr);
if (ptr == nullptr)
{
append(nullptr);
return;
}

while (char data = *ptr++)
{
append_char(data);
}
}

/**
Expand Down

0 comments on commit a322264

Please sign in to comment.