Minor memory optimizatoin of AstUser*Allocator

This commit is contained in:
Geza Lore 2023-10-28 20:31:52 +01:00
parent de4c6065dc
commit e708670f9a
1 changed files with 3 additions and 8 deletions

View File

@ -33,7 +33,7 @@ class AstUserAllocatorBase VL_NOT_FINAL {
static_assert(std::is_base_of<AstNode, T_Node>::value, "T_Node must be an AstNode type"); static_assert(std::is_base_of<AstNode, T_Node>::value, "T_Node must be an AstNode type");
private: private:
std::vector<T_Data*> m_allocated; std::deque<T_Data> m_allocated;
T_Data* getUserp(const T_Node* nodep) const { T_Data* getUserp(const T_Node* nodep) const {
if VL_CONSTEXPR_CXX17 (T_UserN == 1) { if VL_CONSTEXPR_CXX17 (T_UserN == 1) {
@ -83,11 +83,6 @@ protected:
} }
} }
virtual ~AstUserAllocatorBase() {
// Delete all allocated data structures
for (T_Data* const p : m_allocated) { delete p; }
}
VL_UNCOPYABLE(AstUserAllocatorBase); VL_UNCOPYABLE(AstUserAllocatorBase);
public: public:
@ -96,8 +91,8 @@ public:
T_Data& operator()(T_Node* nodep, Args&&... args) { T_Data& operator()(T_Node* nodep, Args&&... args) {
T_Data* userp = getUserp(nodep); T_Data* userp = getUserp(nodep);
if (!userp) { if (!userp) {
userp = new T_Data{std::forward<Args>(args)...}; m_allocated.emplace_back(std::forward<Args>(args)...);
m_allocated.push_back(userp); userp = &m_allocated.back();
setUserp(nodep, userp); setUserp(nodep, userp);
} }
return *userp; return *userp;