зеркало из https://github.com/microsoft/BuildXL.git
Merged PR 648568: Detours - Avoid allocating memory in PathTree destructor
- Avoids allocating wstring and vectors in the destructor Related work items: #1913787
This commit is contained in:
Родитель
ac35dd0ee9
Коммит
11fa4b939d
|
@ -23,9 +23,7 @@ PathTree::PathTree()
|
|||
|
||||
PathTree::~PathTree()
|
||||
{
|
||||
std::vector<std::wstring> descendants;
|
||||
RetrieveAndRemoveAllDescendants(L"", m_root, descendants);
|
||||
|
||||
RemoveAllDescendants(m_root);
|
||||
delete m_root;
|
||||
}
|
||||
|
||||
|
@ -159,6 +157,18 @@ void PathTree::RetrieveAndRemoveAllDescendants(const std::wstring& path, TreeNod
|
|||
node->children.clear();
|
||||
}
|
||||
|
||||
void PathTree::RemoveAllDescendants(TreeNode* node)
|
||||
{
|
||||
for (auto iter = node->children.begin(); iter != node->children.end(); iter++)
|
||||
{
|
||||
RemoveAllDescendants(iter->second);
|
||||
|
||||
delete iter->second;
|
||||
}
|
||||
|
||||
node->children.clear();
|
||||
}
|
||||
|
||||
bool PathTree::TryFind(const std::wstring& path, std::vector<std::pair<std::wstring, TreeNode*>>& nodeTrace)
|
||||
{
|
||||
std::vector<std::wstring> elements;
|
||||
|
|
|
@ -56,6 +56,9 @@ private:
|
|||
// Removes all descendants from the given node and builds the descendants collection using the given path as a prefix
|
||||
void RetrieveAndRemoveAllDescendants(const std::wstring& path, TreeNode* lastNode, std::vector<std::wstring>& descendants);
|
||||
|
||||
// Removes all descendants from the given node
|
||||
void RemoveAllDescendants(TreeNode* node);
|
||||
|
||||
// Debugging facility
|
||||
std::wstring ToDebugString(TreeNode* node = nullptr, std::wstring ident = L"");
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче