summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-10-29 11:22:30 -0400
committerLinus Groh <mail@linusgroh.de>2022-11-01 14:52:59 +0000
commit948bd50197edac59bbb8e0dc37515ddc186eb67a (patch)
treed2887cc4a6d419c56747ecca2523a4f8ca4c023b
parent4283109c13260cf45982852ceac1de572efe7f74 (diff)
downloadserenity-948bd50197edac59bbb8e0dc37515ddc186eb67a.zip
LibSQL: Replace DownPointer copy constructor with move constructor
Avoids awkwardly const-casting the "other" DownPointer.
-rw-r--r--Userland/Libraries/LibSQL/BTree.h2
-rw-r--r--Userland/Libraries/LibSQL/TreeNode.cpp15
2 files changed, 4 insertions, 13 deletions
diff --git a/Userland/Libraries/LibSQL/BTree.h b/Userland/Libraries/LibSQL/BTree.h
index d02222e38d..4a45e832c0 100644
--- a/Userland/Libraries/LibSQL/BTree.h
+++ b/Userland/Libraries/LibSQL/BTree.h
@@ -36,7 +36,7 @@ class DownPointer {
public:
explicit DownPointer(TreeNode*, u32 = 0);
DownPointer(TreeNode*, TreeNode*);
- DownPointer(DownPointer const&);
+ DownPointer(DownPointer&&);
DownPointer(TreeNode*, DownPointer&);
~DownPointer() = default;
[[nodiscard]] u32 pointer() const { return m_pointer; }
diff --git a/Userland/Libraries/LibSQL/TreeNode.cpp b/Userland/Libraries/LibSQL/TreeNode.cpp
index 92ee74d252..1087d46243 100644
--- a/Userland/Libraries/LibSQL/TreeNode.cpp
+++ b/Userland/Libraries/LibSQL/TreeNode.cpp
@@ -34,20 +34,11 @@ DownPointer::DownPointer(TreeNode* owner, DownPointer& down)
{
}
-DownPointer::DownPointer(DownPointer const& other)
+DownPointer::DownPointer(DownPointer&& other)
: m_owner(other.m_owner)
, m_pointer(other.pointer())
+ , m_node(other.m_node ? move(other.m_node) : nullptr)
{
- if (other.m_node)
- // FIXME This is gross. We modify the other object which we promised
- // to be const. However, this particular constructor is needed
- // when we take DownPointers from the Vector they live in when
- // we split a node. The original object is going to go away, so
- // there is no harm done. However, it's yucky. If anybody has
- // a better idea...
- m_node = move(const_cast<DownPointer&>(other).m_node);
- else
- m_node = nullptr;
}
TreeNode* DownPointer::node()
@@ -336,7 +327,7 @@ void TreeNode::split()
down.m_node->m_up = new_node;
}
new_node->m_entries.append(entry);
- new_node->m_down.append(down);
+ new_node->m_down.append(move(down));
}
// Move the median key in the node one level up. Its right node will