Removed last unique_ptr uses, all uses unique_ref now
This commit is contained in:
parent
722c94458b
commit
e64255a16e
@ -74,7 +74,7 @@ unique_ref<DataNode> DataNodeStore::overwriteNodeWith(unique_ref<DataNode> targe
|
|||||||
Key key = target->key();
|
Key key = target->key();
|
||||||
{
|
{
|
||||||
auto targetBlock = target->node().releaseBlock();
|
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());
|
blockstore::utils::copyTo(targetBlock.get(), source.node().block());
|
||||||
}
|
}
|
||||||
auto loaded = load(key);
|
auto loaded = load(key);
|
||||||
@ -84,7 +84,7 @@ unique_ref<DataNode> DataNodeStore::overwriteNodeWith(unique_ref<DataNode> targe
|
|||||||
|
|
||||||
void DataNodeStore::remove(unique_ref<DataNode> node) {
|
void DataNodeStore::remove(unique_ref<DataNode> node) {
|
||||||
auto block = node->node().releaseBlock();
|
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));
|
_blockstore->remove(std::move(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +91,7 @@ optional_ownership_ptr<DataNode> DataTree::createChainOfInnerNodes(unsigned int
|
|||||||
optional_ownership_ptr<DataNode> chain = cpputils::WithoutOwnership<DataNode>(child);
|
optional_ownership_ptr<DataNode> chain = cpputils::WithoutOwnership<DataNode>(child);
|
||||||
for(unsigned int i=0; i<num; ++i) {
|
for(unsigned int i=0; i<num; ++i) {
|
||||||
auto newnode = _nodeStore->createNewInnerNode(*chain);
|
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>(std::move(newnode));
|
||||||
chain = cpputils::WithOwnership<DataNode>(cpputils::to_unique_ptr(std::move(newnode)));
|
|
||||||
}
|
}
|
||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
@ -298,8 +297,7 @@ optional_ownership_ptr<DataLeafNode> DataTree::LastLeaf(DataNode *root) {
|
|||||||
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(root);
|
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(root);
|
||||||
auto lastChild = _nodeStore->load(inner->LastChild()->key());
|
auto lastChild = _nodeStore->load(inner->LastChild()->key());
|
||||||
assert(lastChild != none);
|
assert(lastChild != none);
|
||||||
//TODO Don't use to_unique_ptr but make optional_ownership_ptr work with unique_ref
|
return WithOwnership(LastLeaf(std::move(*lastChild)));
|
||||||
return WithOwnership(cpputils::to_unique_ptr(LastLeaf(std::move(*lastChild))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ref<DataLeafNode> DataTree::LastLeaf(unique_ref<DataNode> root) {
|
unique_ref<DataLeafNode> DataTree::LastLeaf(unique_ref<DataNode> root) {
|
||||||
|
@ -37,7 +37,7 @@ unique_ref<DataTree> DataTreeStore::createNewTree() {
|
|||||||
|
|
||||||
void DataTreeStore::remove(unique_ref<DataTree> tree) {
|
void DataTreeStore::remove(unique_ref<DataTree> tree) {
|
||||||
auto root = tree->releaseRootNode();
|
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));
|
_nodeStore->removeSubtree(std::move(root));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ optional_ownership_ptr<DataInnerNode> GetLowestInnerRightBorderNodeWithCondition
|
|||||||
optional_ownership_ptr<DataInnerNode> currentNode = cpputils::WithoutOwnership(dynamic_cast<DataInnerNode*>(rootNode));
|
optional_ownership_ptr<DataInnerNode> currentNode = cpputils::WithoutOwnership(dynamic_cast<DataInnerNode*>(rootNode));
|
||||||
optional_ownership_ptr<DataInnerNode> result = cpputils::null<DataInnerNode>();
|
optional_ownership_ptr<DataInnerNode> result = cpputils::null<DataInnerNode>();
|
||||||
for (unsigned int i=0; i < rootNode->depth(); ++i) {
|
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
|
//TODO This unnecessarily loads the leaf node in the last loop run
|
||||||
auto lastChild = getLastChildAsInnerNode(nodeStore, *currentNode);
|
auto lastChild = getLastChildAsInnerNode(nodeStore, *currentNode);
|
||||||
if (condition(*currentNode)) {
|
if (condition(*currentNode)) {
|
||||||
@ -42,7 +41,7 @@ optional_ownership_ptr<DataInnerNode> GetLowestInnerRightBorderNodeWithCondition
|
|||||||
}
|
}
|
||||||
assert(lastChild != none || static_cast<int>(i) == rootNode->depth()-1);
|
assert(lastChild != none || static_cast<int>(i) == rootNode->depth()-1);
|
||||||
if (lastChild != none) {
|
if (lastChild != none) {
|
||||||
currentNode = cpputils::to_unique_ptr(std::move(*lastChild));
|
currentNode = cpputils::WithOwnership(std::move(*lastChild));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
unique_ref<DataTree> CreateTree(unique_ref<DataNode> root) {
|
unique_ref<DataTree> CreateTree(unique_ref<DataNode> root) {
|
||||||
Key key = root->key();
|
Key key = root->key();
|
||||||
cpputils::to_unique_ptr(std::move(root)).reset(); //Destruct
|
cpputils::destruct(std::move(root));
|
||||||
return treeStore.load(key).value();
|
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()));
|
uint32_t oldNumberOfLeaves = std::max(1u, ceilDivision(tree->numStoredBytes(), nodeStore->layout().maxBytesPerLeaf()));
|
||||||
TwoLevelDataFixture data(nodeStore, TwoLevelDataFixture::SizePolicy::Unchanged);
|
TwoLevelDataFixture data(nodeStore, TwoLevelDataFixture::SizePolicy::Unchanged);
|
||||||
Key key = tree->key();
|
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());
|
data.FillInto(nodeStore->load(key).get().get());
|
||||||
|
|
||||||
GrowTree(key, newNumberOfLeaves);
|
GrowTree(key, newNumberOfLeaves);
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
unique_ref<DataTree> CreateTree(unique_ref<DataNode> root) {
|
unique_ref<DataTree> CreateTree(unique_ref<DataNode> root) {
|
||||||
Key key = root->key();
|
Key key = root->key();
|
||||||
cpputils::to_unique_ptr(std::move(root)).reset(); // Destruct
|
cpputils::destruct(std::move(root));
|
||||||
return treeStore.load(key).value();
|
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()));
|
uint32_t oldNumberOfLeaves = std::max(1u, ceilDivision(tree->numStoredBytes(), nodeStore->layout().maxBytesPerLeaf()));
|
||||||
TwoLevelDataFixture data(nodeStore, TwoLevelDataFixture::SizePolicy::Unchanged);
|
TwoLevelDataFixture data(nodeStore, TwoLevelDataFixture::SizePolicy::Unchanged);
|
||||||
Key key = tree->key();
|
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());
|
data.FillInto(nodeStore->load(key).get().get());
|
||||||
|
|
||||||
ResizeTree(key, newSize);
|
ResizeTree(key, newSize);
|
||||||
@ -212,7 +212,7 @@ TEST_F(DataTreeTest_ResizeNumBytes, ResizeToZero_NumBytesIsCorrect) {
|
|||||||
auto tree = CreateThreeLevelTreeWithThreeChildrenAndLastLeafSize(10u);
|
auto tree = CreateThreeLevelTreeWithThreeChildrenAndLastLeafSize(10u);
|
||||||
tree->resizeNumBytes(0);
|
tree->resizeNumBytes(0);
|
||||||
Key key = tree->key();
|
Key key = tree->key();
|
||||||
cpputils::to_unique_ptr(std::move(tree)).reset(); // Call destructor
|
cpputils::destruct(std::move(tree));
|
||||||
auto leaf = LoadLeafNode(key);
|
auto leaf = LoadLeafNode(key);
|
||||||
EXPECT_EQ(0u, leaf->numBytes());
|
EXPECT_EQ(0u, leaf->numBytes());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user