Removed last unique_ptr uses, all uses unique_ref now

This commit is contained in:
Sebastian Messmer 2015-07-21 15:24:49 +02:00
parent 722c94458b
commit e64255a16e
6 changed files with 11 additions and 14 deletions

View File

@ -74,7 +74,7 @@ unique_ref<DataNode> DataNodeStore::overwriteNodeWith(unique_ref<DataNode> targe
Key key = target->key();
{
auto targetBlock = target->node().releaseBlock();
cpputils::to_unique_ptr(std::move(target)).reset(); // Call destructor
cpputils::destruct(std::move(target)); // Call destructor
blockstore::utils::copyTo(targetBlock.get(), source.node().block());
}
auto loaded = load(key);
@ -84,7 +84,7 @@ unique_ref<DataNode> DataNodeStore::overwriteNodeWith(unique_ref<DataNode> targe
void DataNodeStore::remove(unique_ref<DataNode> node) {
auto block = node->node().releaseBlock();
cpputils::to_unique_ptr(std::move(node)).reset(); // Call destructor
cpputils::destruct(std::move(node)); // Call destructor
_blockstore->remove(std::move(block));
}

View File

@ -91,8 +91,7 @@ optional_ownership_ptr<DataNode> DataTree::createChainOfInnerNodes(unsigned int
optional_ownership_ptr<DataNode> chain = cpputils::WithoutOwnership<DataNode>(child);
for(unsigned int i=0; i<num; ++i) {
auto newnode = _nodeStore->createNewInnerNode(*chain);
//TODO Don't use to_unique_ptr, but make optional_ownership_ptr work with unique_ref
chain = cpputils::WithOwnership<DataNode>(cpputils::to_unique_ptr(std::move(newnode)));
chain = cpputils::WithOwnership<DataNode>(std::move(newnode));
}
return chain;
}
@ -298,8 +297,7 @@ optional_ownership_ptr<DataLeafNode> DataTree::LastLeaf(DataNode *root) {
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(root);
auto lastChild = _nodeStore->load(inner->LastChild()->key());
assert(lastChild != none);
//TODO Don't use to_unique_ptr but make optional_ownership_ptr work with unique_ref
return WithOwnership(cpputils::to_unique_ptr(LastLeaf(std::move(*lastChild))));
return WithOwnership(LastLeaf(std::move(*lastChild)));
}
unique_ref<DataLeafNode> DataTree::LastLeaf(unique_ref<DataNode> root) {

View File

@ -37,7 +37,7 @@ unique_ref<DataTree> DataTreeStore::createNewTree() {
void DataTreeStore::remove(unique_ref<DataTree> tree) {
auto root = tree->releaseRootNode();
to_unique_ptr(std::move(tree)).reset(); // Destruct tree
cpputils::destruct(std::move(tree)); // Destruct tree
_nodeStore->removeSubtree(std::move(root));
}

View File

@ -34,7 +34,6 @@ optional_ownership_ptr<DataInnerNode> GetLowestInnerRightBorderNodeWithCondition
optional_ownership_ptr<DataInnerNode> currentNode = cpputils::WithoutOwnership(dynamic_cast<DataInnerNode*>(rootNode));
optional_ownership_ptr<DataInnerNode> result = cpputils::null<DataInnerNode>();
for (unsigned int i=0; i < rootNode->depth(); ++i) {
//TODO Don't use to_unique_ptr, but make optional_ownership_ptr work with unique_ref
//TODO This unnecessarily loads the leaf node in the last loop run
auto lastChild = getLastChildAsInnerNode(nodeStore, *currentNode);
if (condition(*currentNode)) {
@ -42,7 +41,7 @@ optional_ownership_ptr<DataInnerNode> GetLowestInnerRightBorderNodeWithCondition
}
assert(lastChild != none || static_cast<int>(i) == rootNode->depth()-1);
if (lastChild != none) {
currentNode = cpputils::to_unique_ptr(std::move(*lastChild));
currentNode = cpputils::WithOwnership(std::move(*lastChild));
}
}

View File

@ -32,7 +32,7 @@ public:
unique_ref<DataTree> CreateTree(unique_ref<DataNode> root) {
Key key = root->key();
cpputils::to_unique_ptr(std::move(root)).reset(); //Destruct
cpputils::destruct(std::move(root));
return treeStore.load(key).value();
}
@ -192,7 +192,7 @@ TEST_P(DataTreeTest_ResizeByTraversing_P, DataStaysIntact) {
uint32_t oldNumberOfLeaves = std::max(1u, ceilDivision(tree->numStoredBytes(), nodeStore->layout().maxBytesPerLeaf()));
TwoLevelDataFixture data(nodeStore, TwoLevelDataFixture::SizePolicy::Unchanged);
Key key = tree->key();
cpputils::to_unique_ptr(std::move(tree)).reset(); // Call destructor
cpputils::destruct(std::move(tree));
data.FillInto(nodeStore->load(key).get().get());
GrowTree(key, newNumberOfLeaves);

View File

@ -32,7 +32,7 @@ public:
unique_ref<DataTree> CreateTree(unique_ref<DataNode> root) {
Key key = root->key();
cpputils::to_unique_ptr(std::move(root)).reset(); // Destruct
cpputils::destruct(std::move(root));
return treeStore.load(key).value();
}
@ -194,7 +194,7 @@ TEST_P(DataTreeTest_ResizeNumBytes_P, DataStaysIntact) {
uint32_t oldNumberOfLeaves = std::max(1u, ceilDivision(tree->numStoredBytes(), nodeStore->layout().maxBytesPerLeaf()));
TwoLevelDataFixture data(nodeStore, TwoLevelDataFixture::SizePolicy::Unchanged);
Key key = tree->key();
cpputils::to_unique_ptr(std::move(tree)).reset(); // Call destructor
cpputils::destruct(std::move(tree));
data.FillInto(nodeStore->load(key).get().get());
ResizeTree(key, newSize);
@ -212,7 +212,7 @@ TEST_F(DataTreeTest_ResizeNumBytes, ResizeToZero_NumBytesIsCorrect) {
auto tree = CreateThreeLevelTreeWithThreeChildrenAndLastLeafSize(10u);
tree->resizeNumBytes(0);
Key key = tree->key();
cpputils::to_unique_ptr(std::move(tree)).reset(); // Call destructor
cpputils::destruct(std::move(tree));
auto leaf = LoadLeafNode(key);
EXPECT_EQ(0u, leaf->numBytes());
}