1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:37:35 +00:00

LibSQL: Replace DownPointer copy constructor with move constructor

Avoids awkwardly const-casting the "other" DownPointer.
This commit is contained in:
Timothy Flynn 2022-10-29 11:22:30 -04:00 committed by Linus Groh
parent 4283109c13
commit 948bd50197
2 changed files with 4 additions and 13 deletions

View file

@ -36,7 +36,7 @@ class DownPointer {
public: public:
explicit DownPointer(TreeNode*, u32 = 0); explicit DownPointer(TreeNode*, u32 = 0);
DownPointer(TreeNode*, TreeNode*); DownPointer(TreeNode*, TreeNode*);
DownPointer(DownPointer const&); DownPointer(DownPointer&&);
DownPointer(TreeNode*, DownPointer&); DownPointer(TreeNode*, DownPointer&);
~DownPointer() = default; ~DownPointer() = default;
[[nodiscard]] u32 pointer() const { return m_pointer; } [[nodiscard]] u32 pointer() const { return m_pointer; }

View file

@ -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_owner(other.m_owner)
, m_pointer(other.pointer()) , 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() TreeNode* DownPointer::node()
@ -336,7 +327,7 @@ void TreeNode::split()
down.m_node->m_up = new_node; down.m_node->m_up = new_node;
} }
new_node->m_entries.append(entry); 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 // Move the median key in the node one level up. Its right node will