From ec598209705473083cf6693c80f54ee15b74325f Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Fri, 25 Jan 2019 19:46:24 +0000 Subject: [PATCH] Use placement new instead of init for metaslab. --- src/mem/metaslab.h | 11 +++-------- src/mem/superslab.h | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/mem/metaslab.h b/src/mem/metaslab.h index 399ffa5..415a67c 100644 --- a/src/mem/metaslab.h +++ b/src/mem/metaslab.h @@ -34,7 +34,7 @@ namespace snmalloc { private: // How many entries are used in this slab. - uint16_t used; + uint16_t used = 0; public: // Bump free list of unused entries in this sizeclass. @@ -59,7 +59,8 @@ namespace snmalloc Mod link; uint8_t sizeclass; - uint8_t next; + // Initially zero to encode the superslabs relative list of slabs. + uint8_t next = 0; void add_use() { @@ -92,12 +93,6 @@ namespace snmalloc head = (uint16_t)~0; } - void init() - { - used = 0; - next = 0; - } - SlabLink* get_link(Slab* slab) { return (SlabLink*)((size_t)slab + link); diff --git a/src/mem/superslab.h b/src/mem/superslab.h index 6c17b30..0d4d79f 100644 --- a/src/mem/superslab.h +++ b/src/mem/superslab.h @@ -94,7 +94,7 @@ namespace snmalloc used = 0; for (size_t i = 0; i < SLAB_COUNT; i++) { - meta[i].init(); + new (&(meta[i])) Metaslab(); } } #ifndef NDEBUG