diff options
author | Matthias Maennich <maennich@google.com> | 2021-07-12 15:58:57 +0100 |
---|---|---|
committer | Matthias Maennich <matthias@maennich.net> | 2021-07-14 07:43:42 +0100 |
commit | 91e6ab8b0a0d56d906880f39b0d428a660edf189 (patch) | |
tree | 4dfd90c9e1111c9913da5ef05ecdb2b8e46bb0da /src/dep.cc | |
parent | f78e6fa37b62376dd9f81402c6e3ca5ad1d5bf0a (diff) | |
download | kati-91e6ab8b0a0d56d906880f39b0d428a660edf189.tar.gz |
dep: remove manual resource management from g_dep_node_pool
Make g_dep_node_pool a vector of DepNode unique_ptr. That way cleanup is
guaranteed and the heap allocation without overhead. Also, move the
ownership responsibility away from the constructor and rather let the
calling site care about the pool. Finally, remove all init/quit code
paths.
Signed-off-by: Matthias Maennich <maennich@google.com>
Diffstat (limited to 'src/dep.cc')
-rw-r--r-- | src/dep.cc | 23 |
1 files changed, 7 insertions, 16 deletions
@@ -36,7 +36,7 @@ namespace { -static vector<DepNode*>* g_dep_node_pool; +static std::vector<std::unique_ptr<DepNode>> g_dep_node_pool; static Symbol ReplaceSuffix(Symbol s, Symbol newsuf) { string r; @@ -287,9 +287,7 @@ DepNode::DepNode(Symbol o, bool p, bool r) is_restat(r), rule_vars(NULL), depfile_var(NULL), - ninja_pool_var(NULL) { - g_dep_node_pool->push_back(this); -} + ninja_pool_var(NULL) {} class DepBuilder { public: @@ -677,8 +675,11 @@ class DepBuilder { return found->second; } - DepNode* n = - new DepNode(output, phony_.exists(output), restat_.exists(output)); + DepNode* n = g_dep_node_pool + .emplace_back(std::make_unique<DepNode>( + output, phony_.exists(output), restat_.exists(output))) + .get(); + done_[output] = n; const RuleMerger* rule_merger = nullptr; @@ -946,16 +947,6 @@ void MakeDep(Evaluator* ev, db.Build(targets, nodes); } -void InitDepNodePool() { - g_dep_node_pool = new vector<DepNode*>; -} - -void QuitDepNodePool() { - for (DepNode* n : *g_dep_node_pool) - delete n; - delete g_dep_node_pool; -} - bool IsSpecialTarget(Symbol output) { return output.get(0) == '.' && output.get(1) != '.'; } |