From a322264c2b0aa47f34f677053e922078eab505b9 Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Sat, 14 Dec 2024 00:23:29 -0500 Subject: [PATCH] simplify dispatch --- src/snmalloc/ds_core/concept.h | 1 + src/snmalloc/ds_core/helpers.h | 42 +++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/snmalloc/ds_core/concept.h b/src/snmalloc/ds_core/concept.h index 2e4824426..996af5fb6 100644 --- a/src/snmalloc/ds_core/concept.h +++ b/src/snmalloc/ds_core/concept.h @@ -71,6 +71,7 @@ namespace snmalloc */ template constexpr bool is_type_complete_v = false; + template constexpr bool is_type_complete_v> = true; diff --git a/src/snmalloc/ds_core/helpers.h b/src/snmalloc/ds_core/helpers.h index 37d0ff7e9..b33ad4686 100644 --- a/src/snmalloc/ds_core/helpers.h +++ b/src/snmalloc/ds_core/helpers.h @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -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(reinterpret_cast(ptr))); - // TODO: CHERI bits. + append("(nullptr)"); } /** - * Append a pointer. + * Append a raw pointer to the buffer as a hex string. */ - template - void append(const T* ptr) + void append(void* ptr) { - if constexpr (std::is_same_v) + if (ptr == nullptr) { - while (char data = *ptr++) - { - append_char(data); - } - } - else - { - append_raw_ptr(ptr); + append(nullptr); + return; } + append(static_cast(reinterpret_cast(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); + } } /**