mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibSQL: Remove Core::EventReceiver parent from SQL::Index
This relationship was only used to provide factory methods for the index (and its BTree child).
This commit is contained in:
parent
1b40bf9783
commit
5ad78cab8d
Notes:
sideshowbarker
2024-07-17 02:28:18 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/5ad78cab8d Pull-request: https://github.com/SerenityOS/serenity/pull/20411 Reviewed-by: https://github.com/gmta ✅
@ -134,7 +134,7 @@ NonnullRefPtr<SQL::BTree> setup_btree(SQL::Serializer& serializer)
|
||||
root_pointer = serializer.heap().request_new_block_index();
|
||||
serializer.heap().set_user_value(0, root_pointer);
|
||||
}
|
||||
auto btree = SQL::BTree::construct(serializer, tuple_descriptor, true, root_pointer);
|
||||
auto btree = MUST(SQL::BTree::create(serializer, tuple_descriptor, true, root_pointer));
|
||||
btree->on_new_root = [&]() {
|
||||
serializer.heap().set_user_value(0, btree->root());
|
||||
};
|
||||
|
@ -9,17 +9,22 @@
|
||||
|
||||
namespace SQL {
|
||||
|
||||
ErrorOr<NonnullRefPtr<BTree>> BTree::create(Serializer& serializer, NonnullRefPtr<TupleDescriptor> const& descriptor, bool unique, Block::Index block_index)
|
||||
{
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) BTree(serializer, descriptor, unique, block_index));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<BTree>> BTree::create(Serializer& serializer, NonnullRefPtr<TupleDescriptor> const& descriptor, Block::Index block_index)
|
||||
{
|
||||
return create(serializer, descriptor, true, block_index);
|
||||
}
|
||||
|
||||
BTree::BTree(Serializer& serializer, NonnullRefPtr<TupleDescriptor> const& descriptor, bool unique, Block::Index block_index)
|
||||
: Index(serializer, descriptor, unique, block_index)
|
||||
, m_root(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
BTree::BTree(Serializer& serializer, NonnullRefPtr<TupleDescriptor> const& descriptor, Block::Index block_index)
|
||||
: BTree(serializer, descriptor, true, block_index)
|
||||
{
|
||||
}
|
||||
|
||||
BTreeIterator BTree::begin()
|
||||
{
|
||||
if (!m_root)
|
||||
|
@ -92,10 +92,9 @@ private:
|
||||
};
|
||||
|
||||
class BTree : public Index {
|
||||
C_OBJECT(BTree);
|
||||
|
||||
public:
|
||||
~BTree() override = default;
|
||||
static ErrorOr<NonnullRefPtr<BTree>> create(Serializer&, NonnullRefPtr<TupleDescriptor> const&, bool unique, Block::Index);
|
||||
static ErrorOr<NonnullRefPtr<BTree>> create(Serializer&, NonnullRefPtr<TupleDescriptor> const&, Block::Index);
|
||||
|
||||
Block::Index root() const { return m_root ? m_root->block_index() : 0; }
|
||||
bool insert(Key const&);
|
||||
@ -110,7 +109,6 @@ public:
|
||||
|
||||
private:
|
||||
BTree(Serializer&, NonnullRefPtr<TupleDescriptor> const&, bool unique, Block::Index);
|
||||
BTree(Serializer&, NonnullRefPtr<TupleDescriptor> const&, Block::Index);
|
||||
void initialize_root();
|
||||
TreeNode* new_root();
|
||||
OwnPtr<TreeNode> m_root { nullptr };
|
||||
|
@ -32,17 +32,17 @@ ResultOr<void> Database::open()
|
||||
VERIFY(!m_open);
|
||||
TRY(m_heap->open());
|
||||
|
||||
m_schemas = BTree::construct(m_serializer, SchemaDef::index_def()->to_tuple_descriptor(), m_heap->schemas_root());
|
||||
m_schemas = TRY(BTree::create(m_serializer, SchemaDef::index_def()->to_tuple_descriptor(), m_heap->schemas_root()));
|
||||
m_schemas->on_new_root = [&]() {
|
||||
m_heap->set_schemas_root(m_schemas->root());
|
||||
};
|
||||
|
||||
m_tables = BTree::construct(m_serializer, TableDef::index_def()->to_tuple_descriptor(), m_heap->tables_root());
|
||||
m_tables = TRY(BTree::create(m_serializer, TableDef::index_def()->to_tuple_descriptor(), m_heap->tables_root()));
|
||||
m_tables->on_new_root = [&]() {
|
||||
m_heap->set_tables_root(m_tables->root());
|
||||
};
|
||||
|
||||
m_table_columns = BTree::construct(m_serializer, ColumnDef::index_def()->to_tuple_descriptor(), m_heap->table_columns_root());
|
||||
m_table_columns = TRY(BTree::create(m_serializer, ColumnDef::index_def()->to_tuple_descriptor(), m_heap->table_columns_root()));
|
||||
m_table_columns->on_new_root = [&]() {
|
||||
m_heap->set_table_columns_root(m_table_columns->root());
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibSQL/Forward.h>
|
||||
#include <LibSQL/Meta.h>
|
||||
#include <LibSQL/Serializer.h>
|
||||
@ -31,11 +31,9 @@ private:
|
||||
Block::Index m_block_index;
|
||||
};
|
||||
|
||||
class Index : public Core::EventReceiver {
|
||||
C_OBJECT_ABSTRACT(Index);
|
||||
|
||||
class Index : public RefCounted<Index> {
|
||||
public:
|
||||
~Index() override = default;
|
||||
virtual ~Index() = default;
|
||||
|
||||
NonnullRefPtr<TupleDescriptor> descriptor() const { return m_descriptor; }
|
||||
[[nodiscard]] bool duplicates_allowed() const { return !m_unique; }
|
||||
|
Loading…
Reference in New Issue
Block a user