diff options
author | Jan de Visser <jan@de-visser.net> | 2021-07-13 13:47:08 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-21 22:03:30 +0200 |
commit | a5e28f2897cf0b93084e964334bc59ac6fd695c1 (patch) | |
tree | 26a25611423903ce9fad77566623a1e8a16e1945 /Tests | |
parent | 9e225d2d05bbed76cd12004397105229c6f27708 (diff) | |
download | serenity-a5e28f2897cf0b93084e964334bc59ac6fd695c1.zip |
LibSQL: Make TupleDescriptor a shared pointer instead of a stack object
Tuple descriptors are basically the same for for example all rows in
a table. Makes sense to share them instead of copying them for every
single row.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibSQL/TestSqlBtreeIndex.cpp | 5 | ||||
-rw-r--r-- | Tests/LibSQL/TestSqlHashIndex.cpp | 6 | ||||
-rw-r--r-- | Tests/LibSQL/TestSqlValueAndTuple.cpp | 24 |
3 files changed, 18 insertions, 17 deletions
diff --git a/Tests/LibSQL/TestSqlBtreeIndex.cpp b/Tests/LibSQL/TestSqlBtreeIndex.cpp index edb3a6b722..c21fcad7ff 100644 --- a/Tests/LibSQL/TestSqlBtreeIndex.cpp +++ b/Tests/LibSQL/TestSqlBtreeIndex.cpp @@ -126,8 +126,8 @@ void insert_into_and_scan_btree(int num_keys); NonnullRefPtr<SQL::BTree> setup_btree(SQL::Heap& heap) { - SQL::TupleDescriptor tuple_descriptor; - tuple_descriptor.append({ "key_value", SQL::SQLType::Integer, SQL::Order::Ascending }); + NonnullRefPtr<SQL::TupleDescriptor> tuple_descriptor = adopt_ref(*new SQL::TupleDescriptor); + tuple_descriptor->append({ "key_value", SQL::SQLType::Integer, SQL::Order::Ascending }); auto root_pointer = heap.user_value(0); if (!root_pointer) { @@ -186,6 +186,7 @@ void insert_into_and_scan_btree(int num_keys) k.set_pointer(pointers[ix]); btree->insert(k); } + #ifdef LIST_TREE btree->list_tree(); #endif diff --git a/Tests/LibSQL/TestSqlHashIndex.cpp b/Tests/LibSQL/TestSqlHashIndex.cpp index c6f0b5badc..ccf2f5988a 100644 --- a/Tests/LibSQL/TestSqlHashIndex.cpp +++ b/Tests/LibSQL/TestSqlHashIndex.cpp @@ -123,9 +123,9 @@ void insert_into_and_scan_hash_index(int num_keys); NonnullRefPtr<SQL::HashIndex> setup_hash_index(SQL::Heap& heap) { - SQL::TupleDescriptor tuple_descriptor; - tuple_descriptor.append({ "key_value", SQL::SQLType::Integer, SQL::Order::Ascending }); - tuple_descriptor.append({ "text_value", SQL::SQLType::Text, SQL::Order::Ascending }); + NonnullRefPtr<SQL::TupleDescriptor> tuple_descriptor = adopt_ref(*new SQL::TupleDescriptor); + tuple_descriptor->append({ "key_value", SQL::SQLType::Integer, SQL::Order::Ascending }); + tuple_descriptor->append({ "text_value", SQL::SQLType::Text, SQL::Order::Ascending }); auto directory_pointer = heap.user_value(0); if (!directory_pointer) { diff --git a/Tests/LibSQL/TestSqlValueAndTuple.cpp b/Tests/LibSQL/TestSqlValueAndTuple.cpp index 7740e5ce48..2c3d6e25d3 100644 --- a/Tests/LibSQL/TestSqlValueAndTuple.cpp +++ b/Tests/LibSQL/TestSqlValueAndTuple.cpp @@ -135,9 +135,9 @@ TEST_CASE(order_int_values) TEST_CASE(tuple) { - SQL::TupleDescriptor descriptor; - descriptor.append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); - descriptor.append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); + NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); + descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); + descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); SQL::Tuple tuple(descriptor); tuple["col1"] = "Test"; @@ -148,9 +148,9 @@ TEST_CASE(tuple) TEST_CASE(serialize_tuple) { - SQL::TupleDescriptor descriptor; - descriptor.append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); - descriptor.append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); + NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); + descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); + descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); SQL::Tuple tuple(descriptor); tuple["col1"] = "Test"; @@ -169,9 +169,9 @@ TEST_CASE(serialize_tuple) TEST_CASE(copy_tuple) { - SQL::TupleDescriptor descriptor; - descriptor.append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); - descriptor.append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); + NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); + descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); + descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); SQL::Tuple tuple(descriptor); tuple["col1"] = "Test"; @@ -187,9 +187,9 @@ TEST_CASE(copy_tuple) TEST_CASE(compare_tuples) { - SQL::TupleDescriptor descriptor; - descriptor.append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); - descriptor.append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); + NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); + descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); + descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); SQL::Tuple tuple1(descriptor); tuple1["col1"] = "Test"; |