From 875c20202cccc6e1a782df6aac161637d0f673fc Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 31 Jan 2023 13:46:00 +0000 Subject: [PATCH] Code review changes. --- src/snmalloc/backend_helpers/smallbuddyrange.h | 15 +++++++++------ src/snmalloc/ds_core/defines.h | 6 ++++++ src/snmalloc/mem/freelist.h | 14 ++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/snmalloc/backend_helpers/smallbuddyrange.h b/src/snmalloc/backend_helpers/smallbuddyrange.h index 641c8cd9..c672478f 100644 --- a/src/snmalloc/backend_helpers/smallbuddyrange.h +++ b/src/snmalloc/backend_helpers/smallbuddyrange.h @@ -155,12 +155,15 @@ namespace snmalloc */ static void clear(Contents p) { -#ifdef SNMALLOC_CLEAN_POINTERS - p->left = nullptr; - p->right = nullptr; -#else - UNUSED(p); -#endif + if constexpr (CLEAN_POINTERS) + { + p->left = nullptr; + p->right = nullptr; + } + else + { + UNUSED(p); + } } }; diff --git a/src/snmalloc/ds_core/defines.h b/src/snmalloc/ds_core/defines.h index 7ddd5691..8a517d8a 100644 --- a/src/snmalloc/ds_core/defines.h +++ b/src/snmalloc/ds_core/defines.h @@ -225,6 +225,12 @@ namespace snmalloc #else static constexpr bool CHECK_CLIENT = false; #endif + +#ifdef SNMALLOC_CLEAN_POINTERS + static constexpr bool CLEAN_POINTERS = true; +#else + static constexpr bool CLEAN_POINTERS = false; +#endif } // namespace snmalloc #ifdef SNMALLOC_CHECK_CLIENT diff --git a/src/snmalloc/mem/freelist.h b/src/snmalloc/mem/freelist.h index 0fda358e..e84d2c24 100644 --- a/src/snmalloc/mem/freelist.h +++ b/src/snmalloc/mem/freelist.h @@ -192,12 +192,14 @@ namespace snmalloc */ void cleanup() { -#ifdef SNMALLOC_CLEAN_POINTERS - this->next_object = nullptr; -# ifdef SNMALLOC_CHECK_CLIENT - this->prev_encoded = 0; -# endif -#endif + if constexpr (CLEAN_POINTERS) + { + this->next_object = nullptr; + if constexpr (CHECK_CLIENT) + { + this->prev_encoded = 0; + } + } } };