From 1cb9772a40f196f29d64c7c367761e0590e73222 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 5 May 2018 18:27:50 +0200 Subject: [PATCH] src: remove unused freelist.h header Always easy enough to re-introduce if we do need it. PR-URL: https://github.com/nodejs/node/pull/20544 Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Daniel Bevenius Reviewed-By: Matheus Marchini Reviewed-By: Tiancheng "Timothy" Gu --- src/freelist.h | 92 -------------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 src/freelist.h diff --git a/src/freelist.h b/src/freelist.h deleted file mode 100644 index 7dff56a35d348a..00000000000000 --- a/src/freelist.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef SRC_FREELIST_H_ -#define SRC_FREELIST_H_ - -#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#include "util.h" - -namespace node { - -struct DefaultFreelistTraits; - -template -class Freelist { - public: - typedef struct list_item { - T* item = nullptr; - list_item* next = nullptr; - } list_item; - - Freelist() {} - ~Freelist() { - while (head_ != nullptr) { - list_item* item = head_; - head_ = item->next; - FreelistTraits::Free(item->item); - free(item); - } - } - - void push(T* item) { - if (size_ > kMaximumLength) { - FreelistTraits::Free(item); - } else { - size_++; - FreelistTraits::Reset(item); - list_item* li = Calloc(1); - li->item = item; - if (head_ == nullptr) { - head_ = li; - tail_ = li; - } else { - tail_->next = li; - tail_ = li; - } - } - } - - T* pop() { - if (head_ != nullptr) { - size_--; - list_item* cur = head_; - T* item = cur->item; - head_ = cur->next; - free(cur); - return item; - } else { - return FreelistTraits::template Alloc(); - } - } - - private: - size_t size_ = 0; - list_item* head_ = nullptr; - list_item* tail_ = nullptr; -}; - -struct DefaultFreelistTraits { - template - static T* Alloc() { - return ::new (Malloc(1)) T(); - } - - template - static void Free(T* item) { - item->~T(); - free(item); - } - - template - static void Reset(T* item) { - item->~T(); - ::new (item) T(); - } -}; - -} // namespace node - -#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#endif // SRC_FREELIST_H_