LibSQL: Clean up code style and remove unused includes
No functional changes.
This commit is contained in:
parent
8992ff5aeb
commit
a99c1297e0
Notes:
sideshowbarker
2024-07-17 07:25:39 +09:00
Author: https://github.com/gmta Commit: https://github.com/SerenityOS/serenity/commit/a99c1297e0 Pull-request: https://github.com/SerenityOS/serenity/pull/18476 Reviewed-by: https://github.com/trflynn89 ✅
14 changed files with 43 additions and 96 deletions
|
@ -208,9 +208,8 @@ void insert_into_and_scan_btree(int num_keys)
|
|||
SQL::Tuple prev;
|
||||
for (auto iter = btree->begin(); !iter.is_end(); iter++, count++) {
|
||||
auto key = (*iter);
|
||||
if (prev.size()) {
|
||||
if (prev.size())
|
||||
EXPECT(prev < key);
|
||||
}
|
||||
auto key_value = key[0].to_int<i32>();
|
||||
for (auto ix = 0; ix < num_keys; ix++) {
|
||||
if (keys[ix] == key_value) {
|
||||
|
|
|
@ -133,9 +133,8 @@ BTreeIterator BTreeIterator::next() const
|
|||
// end (which is really the beginning) of the tree.
|
||||
BTreeIterator BTreeIterator::previous() const
|
||||
{
|
||||
if (is_end()) {
|
||||
if (is_end())
|
||||
return end();
|
||||
}
|
||||
|
||||
auto node = m_current;
|
||||
auto ix = m_index;
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/RefPtr.h>
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <LibSQL/BTree.h>
|
||||
#include <LibSQL/Database.h>
|
||||
#include <LibSQL/Heap.h>
|
||||
|
@ -174,9 +173,8 @@ ErrorOr<Vector<Row>> Database::select_all(TableDef& table)
|
|||
{
|
||||
VERIFY(m_table_cache.get(table.key().hash()).has_value());
|
||||
Vector<Row> ret;
|
||||
for (auto pointer = table.pointer(); pointer; pointer = ret.last().next_pointer()) {
|
||||
for (auto pointer = table.pointer(); pointer; pointer = ret.last().next_pointer())
|
||||
ret.append(m_serializer.deserialize_block<Row>(pointer, table, pointer));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,9 +86,8 @@ void HashBucket::serialize(Serializer& serializer) const
|
|||
pointer(), index(), local_depth(), size());
|
||||
serializer.serialize<u32>(local_depth());
|
||||
serializer.serialize<u32>(size());
|
||||
for (auto& key : m_entries) {
|
||||
for (auto& key : m_entries)
|
||||
serializer.serialize<Key>(key);
|
||||
}
|
||||
}
|
||||
|
||||
void HashBucket::deserialize(Serializer& serializer)
|
||||
|
@ -111,9 +110,8 @@ void HashBucket::deserialize(Serializer& serializer)
|
|||
size_t HashBucket::length() const
|
||||
{
|
||||
size_t len = 2 * sizeof(u32);
|
||||
for (auto& key : m_entries) {
|
||||
for (auto& key : m_entries)
|
||||
len += key.length();
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
@ -132,9 +130,8 @@ bool HashBucket::insert(Key const& key)
|
|||
{
|
||||
if (!m_inflated)
|
||||
m_hash_index.serializer().deserialize_block_to(pointer(), *this);
|
||||
if (find_key_in_bucket(key).has_value()) {
|
||||
if (find_key_in_bucket(key).has_value())
|
||||
return false;
|
||||
}
|
||||
if ((length() + key.length()) > BLOCKSIZE) {
|
||||
dbgln_if(SQL_DEBUG, "Adding key {} would make length exceed block size", key.to_deprecated_string());
|
||||
return false;
|
||||
|
@ -148,9 +145,8 @@ Optional<size_t> HashBucket::find_key_in_bucket(Key const& key)
|
|||
{
|
||||
for (auto ix = 0u; ix < size(); ix++) {
|
||||
auto& k = entries()[ix];
|
||||
if (k == key) {
|
||||
if (k == key)
|
||||
return ix;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@ -199,9 +195,8 @@ void HashBucket::list_bucket()
|
|||
{
|
||||
warnln("Bucket #{} size {} local depth {} pointer {}{}",
|
||||
index(), size(), local_depth(), pointer(), (pointer() ? "" : " (VIRTUAL)"));
|
||||
for (auto& key : entries()) {
|
||||
for (auto& key : entries())
|
||||
warnln(" {} hash {}", key.to_deprecated_string(), key.hash());
|
||||
}
|
||||
}
|
||||
|
||||
HashIndex::HashIndex(Serializer& serializer, NonnullRefPtr<TupleDescriptor> const& descriptor, u32 first_node)
|
||||
|
@ -209,9 +204,8 @@ HashIndex::HashIndex(Serializer& serializer, NonnullRefPtr<TupleDescriptor> cons
|
|||
, m_nodes()
|
||||
, m_buckets()
|
||||
{
|
||||
if (!first_node) {
|
||||
if (!first_node)
|
||||
set_pointer(new_record_pointer());
|
||||
}
|
||||
if (serializer.has_block(first_node)) {
|
||||
u32 pointer = first_node;
|
||||
do {
|
||||
|
@ -272,9 +266,8 @@ HashBucket* HashIndex::get_bucket_for_insert(Key const& key)
|
|||
auto moved = 0;
|
||||
for (auto entry_index = (int)bucket->m_entries.size() - 1; entry_index >= 0; entry_index--) {
|
||||
if (bucket->m_entries[entry_index].hash() % size() == ix) {
|
||||
if (!sub_bucket->pointer()) {
|
||||
if (!sub_bucket->pointer())
|
||||
sub_bucket->set_pointer(new_record_pointer());
|
||||
}
|
||||
sub_bucket->insert(bucket->m_entries.take(entry_index));
|
||||
moved++;
|
||||
}
|
||||
|
@ -389,18 +382,12 @@ void HashIndex::list_hash()
|
|||
{
|
||||
warnln("Number of buckets: {} (Global depth {})", size(), global_depth());
|
||||
warn("Directory pointer(s): ");
|
||||
for (auto ptr : m_nodes) {
|
||||
for (auto ptr : m_nodes)
|
||||
warn("{}, ", ptr);
|
||||
}
|
||||
warnln();
|
||||
|
||||
bool first_bucket = true;
|
||||
for (auto& bucket : m_buckets) {
|
||||
if (first_bucket) {
|
||||
first_bucket = false;
|
||||
}
|
||||
for (auto& bucket : m_buckets)
|
||||
bucket->list_bucket();
|
||||
}
|
||||
}
|
||||
|
||||
HashIndexIterator::HashIndexIterator(HashBucket const* bucket, size_t index)
|
||||
|
|
|
@ -10,9 +10,7 @@
|
|||
#include <LibCore/IODevice.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibSQL/Heap.h>
|
||||
#include <LibSQL/Serializer.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace SQL {
|
||||
|
||||
|
@ -169,9 +167,8 @@ ErrorOr<void> Heap::flush()
|
|||
{
|
||||
VERIFY(m_file);
|
||||
Vector<u32> blocks;
|
||||
for (auto& wal_entry : m_write_ahead_log) {
|
||||
for (auto& wal_entry : m_write_ahead_log)
|
||||
blocks.append(wal_entry.key);
|
||||
}
|
||||
quick_sort(blocks);
|
||||
for (auto& block : blocks) {
|
||||
auto buffer_it = m_write_ahead_log.find(block);
|
||||
|
@ -221,9 +218,8 @@ ErrorOr<void> Heap::read_zero_block()
|
|||
|
||||
memcpy(m_user_values.data(), buffer.offset_pointer(USER_VALUES_OFFSET), m_user_values.size() * sizeof(u32));
|
||||
for (auto ix = 0u; ix < m_user_values.size(); ix++) {
|
||||
if (m_user_values[ix]) {
|
||||
if (m_user_values[ix])
|
||||
dbgln_if(SQL_DEBUG, "User value {}: {}", ix, m_user_values[ix]);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@ -237,9 +233,8 @@ void Heap::update_zero_block()
|
|||
dbgln_if(SQL_DEBUG, "Table Columns root node: {}", m_table_columns_root);
|
||||
dbgln_if(SQL_DEBUG, "Free list: {}", m_free_list);
|
||||
for (auto ix = 0u; ix < m_user_values.size(); ix++) {
|
||||
if (m_user_values[ix]) {
|
||||
if (m_user_values[ix])
|
||||
dbgln_if(SQL_DEBUG, "User value {}: {}", ix, m_user_values[ix]);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Handle an OOM failure here.
|
||||
|
@ -263,9 +258,8 @@ void Heap::initialize_zero_block()
|
|||
m_table_columns_root = 0;
|
||||
m_next_block = 1;
|
||||
m_free_list = 0;
|
||||
for (auto& user : m_user_values) {
|
||||
for (auto& user : m_user_values)
|
||||
user = 0u;
|
||||
}
|
||||
update_zero_block();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <AK/Debug.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Object.h>
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <LibSQL/Heap.h>
|
||||
#include <LibSQL/Index.h>
|
||||
#include <LibSQL/Meta.h>
|
||||
#include <LibSQL/TupleDescriptor.h>
|
||||
|
||||
namespace SQL {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/Result.h>
|
||||
#include <AK/Vector.h>
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace SQL {
|
|||
|
||||
void Serializer::serialize(DeprecatedString const& text)
|
||||
{
|
||||
serialize<u32>((u32)text.length());
|
||||
serialize<u32>(text.length());
|
||||
if (!text.is_empty())
|
||||
write((u8 const*)text.characters(), text.length());
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <AK/Debug.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <LibSQL/Forward.h>
|
||||
#include <LibSQL/Heap.h>
|
||||
#include <string.h>
|
||||
|
@ -155,9 +154,8 @@ private:
|
|||
StringBuilder builder;
|
||||
builder.appendff("{0} {1:04x} | ", prefix, sz);
|
||||
Vector<DeprecatedString> bytes;
|
||||
for (auto ix = 0u; ix < sz; ++ix) {
|
||||
for (auto ix = 0u; ix < sz; ++ix)
|
||||
bytes.append(DeprecatedString::formatted("{0:02x}", *(ptr + ix)));
|
||||
}
|
||||
StringBuilder bytes_builder;
|
||||
bytes_builder.join(' ', bytes);
|
||||
builder.append(bytes_builder.to_deprecated_string());
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibSQL/BTree.h>
|
||||
#include <LibSQL/Serializer.h>
|
||||
|
@ -145,9 +144,8 @@ size_t TreeNode::length() const
|
|||
if (!size())
|
||||
return 0;
|
||||
size_t len = sizeof(u32);
|
||||
for (auto& key : m_entries) {
|
||||
for (auto& key : m_entries)
|
||||
len += sizeof(u32) + key.length();
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
@ -315,9 +313,8 @@ void TreeNode::split()
|
|||
auto down = m_down.take(median_index);
|
||||
|
||||
// Reparent to new right node:
|
||||
if (down.m_node != nullptr) {
|
||||
if (down.m_node != nullptr)
|
||||
down.m_node->m_up = new_node;
|
||||
}
|
||||
new_node->m_entries.append(entry);
|
||||
new_node->m_down.append(move(down));
|
||||
}
|
||||
|
@ -354,15 +351,13 @@ void TreeNode::dump_if(int flag, DeprecatedString&& msg)
|
|||
VERIFY(m_down[ix].pointer() == 0);
|
||||
builder.appendff("'{}' ", (DeprecatedString)m_entries[ix]);
|
||||
}
|
||||
if (!is_leaf()) {
|
||||
if (!is_leaf())
|
||||
builder.appendff("[v{}]", m_down[size()].pointer());
|
||||
} else {
|
||||
else
|
||||
VERIFY(m_down[size()].pointer() == 0);
|
||||
}
|
||||
builder.appendff(" (size {}", (int)size());
|
||||
if (is_leaf()) {
|
||||
if (is_leaf())
|
||||
builder.append(", leaf"sv);
|
||||
}
|
||||
builder.append(')');
|
||||
dbgln(builder.to_deprecated_string());
|
||||
}
|
||||
|
@ -370,22 +365,19 @@ void TreeNode::dump_if(int flag, DeprecatedString&& msg)
|
|||
void TreeNode::list_node(int indent)
|
||||
{
|
||||
auto do_indent = [&]() {
|
||||
for (int i = 0; i < indent; ++i) {
|
||||
for (int i = 0; i < indent; ++i)
|
||||
warn(" ");
|
||||
}
|
||||
};
|
||||
do_indent();
|
||||
warnln("--> #{}", pointer());
|
||||
for (auto ix = 0u; ix < size(); ix++) {
|
||||
if (!is_leaf()) {
|
||||
if (!is_leaf())
|
||||
down_node(ix)->list_node(indent + 2);
|
||||
}
|
||||
do_indent();
|
||||
warnln("{}", m_entries[ix].to_deprecated_string());
|
||||
}
|
||||
if (!is_leaf()) {
|
||||
if (!is_leaf())
|
||||
down_node(size())->list_node(indent + 2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibSQL/Serializer.h>
|
||||
|
@ -26,9 +24,8 @@ Tuple::Tuple(NonnullRefPtr<TupleDescriptor> const& descriptor, u32 pointer)
|
|||
, m_data()
|
||||
, m_pointer(pointer)
|
||||
{
|
||||
for (auto& element : *descriptor) {
|
||||
for (auto& element : *descriptor)
|
||||
m_data.empend(element.type);
|
||||
}
|
||||
}
|
||||
|
||||
Tuple::Tuple(NonnullRefPtr<TupleDescriptor> const& descriptor, Serializer& serializer)
|
||||
|
@ -42,10 +39,10 @@ void Tuple::deserialize(Serializer& serializer)
|
|||
dbgln_if(SQL_DEBUG, "deserialize tuple at offset {}", serializer.offset());
|
||||
serializer.deserialize_to<u32>(m_pointer);
|
||||
dbgln_if(SQL_DEBUG, "pointer: {}", m_pointer);
|
||||
auto sz = serializer.deserialize<u32>();
|
||||
auto number_of_elements = serializer.deserialize<u32>();
|
||||
m_data.clear();
|
||||
m_descriptor->clear();
|
||||
for (auto ix = 0u; ix < sz; ++ix) {
|
||||
for (auto ix = 0u; ix < number_of_elements; ++ix) {
|
||||
m_descriptor->append(serializer.deserialize<TupleElementDescriptor>());
|
||||
m_data.append(serializer.deserialize<Value>());
|
||||
}
|
||||
|
@ -56,11 +53,10 @@ void Tuple::serialize(Serializer& serializer) const
|
|||
VERIFY(m_descriptor->size() == m_data.size());
|
||||
dbgln_if(SQL_DEBUG, "Serializing tuple pointer {}", pointer());
|
||||
serializer.serialize<u32>(pointer());
|
||||
serializer.serialize<u32>((u32)m_descriptor->size());
|
||||
serializer.serialize<u32>(m_descriptor->size());
|
||||
for (auto ix = 0u; ix < m_descriptor->size(); ix++) {
|
||||
auto& key_part = m_data[ix];
|
||||
serializer.serialize<TupleElementDescriptor>((*m_descriptor)[ix]);
|
||||
serializer.serialize<Value>(key_part);
|
||||
serializer.serialize<Value>(m_data[ix]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,9 +69,8 @@ Tuple::Tuple(Tuple const& other)
|
|||
|
||||
Tuple& Tuple::operator=(Tuple const& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
if (this != &other)
|
||||
copy_from(other);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -83,9 +78,8 @@ Optional<size_t> Tuple::index_of(StringView name) const
|
|||
{
|
||||
for (auto ix = 0u; ix < m_descriptor->size(); ix++) {
|
||||
auto& part = (*m_descriptor)[ix];
|
||||
if (part.name == name) {
|
||||
if (part.name == name)
|
||||
return ix;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@ -107,9 +101,8 @@ Value& Tuple::operator[](DeprecatedString const& name)
|
|||
void Tuple::append(Value const& value)
|
||||
{
|
||||
VERIFY(descriptor()->size() >= size());
|
||||
if (descriptor()->size() == size()) {
|
||||
if (descriptor()->size() == size())
|
||||
descriptor()->append(value.descriptor());
|
||||
}
|
||||
m_data.append(value);
|
||||
}
|
||||
|
||||
|
@ -122,9 +115,8 @@ Tuple& Tuple::operator+=(Value const& value)
|
|||
void Tuple::extend(Tuple const& other)
|
||||
{
|
||||
VERIFY((descriptor()->size() == size()) || (descriptor()->size() >= size() + other.size()));
|
||||
if (descriptor()->size() == size()) {
|
||||
if (descriptor()->size() == size())
|
||||
descriptor()->extend(other.descriptor());
|
||||
}
|
||||
m_data.extend(other.m_data);
|
||||
}
|
||||
|
||||
|
@ -165,14 +157,12 @@ DeprecatedString Tuple::to_deprecated_string() const
|
|||
{
|
||||
StringBuilder builder;
|
||||
for (auto& part : m_data) {
|
||||
if (!builder.is_empty()) {
|
||||
if (!builder.is_empty())
|
||||
builder.append('|');
|
||||
}
|
||||
builder.append(part.to_deprecated_string());
|
||||
}
|
||||
if (pointer() != 0) {
|
||||
if (pointer() != 0)
|
||||
builder.appendff(":{}", pointer());
|
||||
}
|
||||
return builder.to_deprecated_string();
|
||||
}
|
||||
|
||||
|
@ -180,14 +170,12 @@ void Tuple::copy_from(Tuple const& other)
|
|||
{
|
||||
if (*m_descriptor != *other.m_descriptor) {
|
||||
m_descriptor->clear();
|
||||
for (TupleElementDescriptor const& part : *other.m_descriptor) {
|
||||
for (TupleElementDescriptor const& part : *other.m_descriptor)
|
||||
m_descriptor->append(part);
|
||||
}
|
||||
}
|
||||
m_data.clear();
|
||||
for (auto& part : other.m_data) {
|
||||
for (auto& part : other.m_data)
|
||||
m_data.append(part);
|
||||
}
|
||||
m_pointer = other.pointer();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ struct TupleElementDescriptor {
|
|||
|
||||
size_t length() const
|
||||
{
|
||||
return (sizeof(u32) + name.length()) + 2 * sizeof(u8);
|
||||
return sizeof(u32) + name.length() + 2 * sizeof(u8);
|
||||
}
|
||||
|
||||
DeprecatedString to_deprecated_string() const
|
||||
|
@ -85,18 +85,16 @@ public:
|
|||
size_t length() const
|
||||
{
|
||||
size_t len = sizeof(u32);
|
||||
for (auto& element : *this) {
|
||||
for (auto& element : *this)
|
||||
len += element.length();
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
DeprecatedString to_deprecated_string() const
|
||||
{
|
||||
Vector<DeprecatedString> elements;
|
||||
for (auto& element : *this) {
|
||||
for (auto& element : *this)
|
||||
elements.append(element.to_deprecated_string());
|
||||
}
|
||||
return DeprecatedString::formatted("[\n{}\n]", DeprecatedString::join('\n', elements));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <LibSQL/Serializer.h>
|
||||
#include <LibSQL/TupleDescriptor.h>
|
||||
#include <LibSQL/Value.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace SQL {
|
||||
|
||||
|
@ -738,7 +737,6 @@ void Value::deserialize(Serializer& serializer)
|
|||
switch (m_type) {
|
||||
case SQLType::Null:
|
||||
VERIFY_NOT_REACHED();
|
||||
break;
|
||||
case SQLType::Text:
|
||||
m_value = serializer.deserialize<DeprecatedString>();
|
||||
break;
|
||||
|
@ -770,7 +768,6 @@ void Value::deserialize(Serializer& serializer)
|
|||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SQLType::Float:
|
||||
|
|
Loading…
Add table
Reference in a new issue