diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2013-01-04 22:35:42 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2013-01-04 22:35:42 +0000 |
commit | 4ccabc1da94f6da9d9a49c0a5020b309aced67bf (patch) | |
tree | 0b8aa0dcd72b4eeeb32a33bc373dbd5afa614c9e /llvm/unittests/ADT/ilistTest.cpp | |
parent | 7f92b7ad0aa69a961154b88df90474ac38f076ac (diff) | |
download | bcm5719-llvm-4ccabc1da94f6da9d9a49c0a5020b309aced67bf.tar.gz bcm5719-llvm-4ccabc1da94f6da9d9a49c0a5020b309aced67bf.zip |
Add an iplist::clearAndLeakNodesUnsafely() function.
The iplist::clear() function can be quite expensive because it traverses
the entire list, calling deleteNode() and removeNodeFromList() on each
element. If node destruction and deallocation can be handled some other
way, clearAndLeakNodesUnsafely() can be used to jettison all nodes
without bringing them into cache.
The function name is meant to be ominous.
llvm-svn: 171540
Diffstat (limited to 'llvm/unittests/ADT/ilistTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/ilistTest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/ilistTest.cpp b/llvm/unittests/ADT/ilistTest.cpp index 07bd5ec6019..0c0cd0fd56f 100644 --- a/llvm/unittests/ADT/ilistTest.cpp +++ b/llvm/unittests/ADT/ilistTest.cpp @@ -22,6 +22,7 @@ struct Node : ilist_node<Node> { Node() {} Node(int _Value) : Value(_Value) {} + ~Node() { Value = -1; } }; TEST(ilistTest, Basic) { @@ -62,4 +63,36 @@ TEST(ilistTest, SpliceOne) { EXPECT_EQ(3, List.back().Value); } +TEST(ilistTest, UnsafeClear) { + ilist<Node> List; + + // Before even allocating a sentinel. + List.clearAndLeakNodesUnsafely(); + EXPECT_EQ(0u, List.size()); + + // Empty list with sentinel. + ilist<Node>::iterator E = List.end(); + List.clearAndLeakNodesUnsafely(); + EXPECT_EQ(0u, List.size()); + // The sentinel shouldn't change. + EXPECT_TRUE(E == List.end()); + + // List with contents. + List.push_back(1); + ASSERT_EQ(1u, List.size()); + Node *N = List.begin(); + EXPECT_EQ(1, N->Value); + List.clearAndLeakNodesUnsafely(); + EXPECT_EQ(0u, List.size()); + ASSERT_EQ(1, N->Value); + delete N; + + // List is still functional. + List.push_back(5); + List.push_back(6); + ASSERT_EQ(2u, List.size()); + EXPECT_EQ(5, List.front().Value); + EXPECT_EQ(6, List.back().Value); +} + } |