summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-11-24 19:42:20 (GMT)
committerBrad King <brad.king@kitware.com>2015-11-25 15:33:26 (GMT)
commit85fe26b5f742b704b51a7e15b4806366feab3a23 (patch)
tree294da30211b0f673b15755a4ef3c897d67e870d5
parent518d6b22f6705c4747c713031587705641540364 (diff)
downloadCMake-85fe26b5f742b704b51a7e15b4806366feab3a23.zip
CMake-85fe26b5f742b704b51a7e15b4806366feab3a23.tar.gz
CMake-85fe26b5f742b704b51a7e15b4806366feab3a23.tar.bz2
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.
-rw-r--r--Source/cmLinkedTree.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/Source/cmLinkedTree.h b/Source/cmLinkedTree.h
index 93d801e..3b41459 100644
--- a/Source/cmLinkedTree.h
+++ b/Source/cmLinkedTree.h
@@ -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);