Kaynağa Gözat

LibSQL: Replace DownPointer copy constructor with move constructor

Avoids awkwardly const-casting the "other" DownPointer.
Timothy Flynn 2 yıl önce
ebeveyn
işleme
948bd50197

+ 1 - 1
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; }

+ 3 - 12
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