mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +08:00
cmLinkedTree: Add Pop method
Add a method to increment an iterator (follow the "up" pointer) to the previous level in the stack of scopes and free storage of the top of the stack if possible. This will allow short-lived scopes to be created and destroyed by matching Push/Pop pairs without accumulating storage.
This commit is contained in:
@@ -152,6 +152,27 @@ public:
|
||||
return Push_impl(it, t);
|
||||
}
|
||||
|
||||
bool IsLast(iterator it)
|
||||
{
|
||||
return it.Position == this->Data.size();
|
||||
}
|
||||
|
||||
iterator Pop(iterator it)
|
||||
{
|
||||
assert(!this->Data.empty());
|
||||
assert(this->UpPositions.size() == this->Data.size());
|
||||
bool const isLast = this->IsLast(it);
|
||||
++it;
|
||||
// If this is the last entry then no other entry can refer
|
||||
// to it so we can drop its storage.
|
||||
if (isLast)
|
||||
{
|
||||
this->Data.pop_back();
|
||||
this->UpPositions.pop_back();
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
iterator Truncate()
|
||||
{
|
||||
assert(this->UpPositions.size() > 0);
|
||||
|
Reference in New Issue
Block a user