summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2023-04-19 19:03:00 +0200
committerTim Flynn <trflynn89@pm.me>2023-04-23 18:08:17 -0400
commita99c1297e0e5a17797b40b27da50b8b5f92442cf (patch)
treea36fe2dce9513083282db47ac78ac8d64b9cd265 /Userland
parent8992ff5aebb2a555baed55f63beae1053c293746 (diff)
downloadserenity-a99c1297e0e5a17797b40b27da50b8b5f92442cf.zip
LibSQL: Clean up code style and remove unused includes
No functional changes.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibSQL/BTreeIterator.cpp3
-rw-r--r--Userland/Libraries/LibSQL/Database.cpp6
-rw-r--r--Userland/Libraries/LibSQL/HashIndex.cpp31
-rw-r--r--Userland/Libraries/LibSQL/Heap.cpp14
-rw-r--r--Userland/Libraries/LibSQL/Heap.h1
-rw-r--r--Userland/Libraries/LibSQL/Index.cpp1
-rw-r--r--Userland/Libraries/LibSQL/Meta.h1
-rw-r--r--Userland/Libraries/LibSQL/Serializer.cpp2
-rw-r--r--Userland/Libraries/LibSQL/Serializer.h4
-rw-r--r--Userland/Libraries/LibSQL/TreeNode.cpp24
-rw-r--r--Userland/Libraries/LibSQL/Tuple.cpp38
-rw-r--r--Userland/Libraries/LibSQL/TupleDescriptor.h8
-rw-r--r--Userland/Libraries/LibSQL/Value.cpp3
13 files changed, 42 insertions, 94 deletions
diff --git a/Userland/Libraries/LibSQL/BTreeIterator.cpp b/Userland/Libraries/LibSQL/BTreeIterator.cpp
index 548355e7c4..13ac641c87 100644
--- a/Userland/Libraries/LibSQL/BTreeIterator.cpp
+++ b/Userland/Libraries/LibSQL/BTreeIterator.cpp
@@ -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;
diff --git a/Userland/Libraries/LibSQL/Database.cpp b/Userland/Libraries/LibSQL/Database.cpp
index edb067fefd..33e6b17d0e 100644
--- a/Userland/Libraries/LibSQL/Database.cpp
+++ b/Userland/Libraries/LibSQL/Database.cpp
@@ -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;
}
diff --git a/Userland/Libraries/LibSQL/HashIndex.cpp b/Userland/Libraries/LibSQL/HashIndex.cpp
index df7f4a56ff..25a8b5c272 100644
--- a/Userland/Libraries/LibSQL/HashIndex.cpp
+++ b/Userland/Libraries/LibSQL/HashIndex.cpp
@@ -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)
diff --git a/Userland/Libraries/LibSQL/Heap.cpp b/Userland/Libraries/LibSQL/Heap.cpp
index 6b897a4fed..93c466b977 100644
--- a/Userland/Libraries/LibSQL/Heap.cpp
+++ b/Userland/Libraries/LibSQL/Heap.cpp
@@ -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();
}
diff --git a/Userland/Libraries/LibSQL/Heap.h b/Userland/Libraries/LibSQL/Heap.h
index 19c5b6231e..6add15fba6 100644
--- a/Userland/Libraries/LibSQL/Heap.h
+++ b/Userland/Libraries/LibSQL/Heap.h
@@ -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>
diff --git a/Userland/Libraries/LibSQL/Index.cpp b/Userland/Libraries/LibSQL/Index.cpp
index 59497fe9d3..5306a14799 100644
--- a/Userland/Libraries/LibSQL/Index.cpp
+++ b/Userland/Libraries/LibSQL/Index.cpp
@@ -6,7 +6,6 @@
#include <LibSQL/Heap.h>
#include <LibSQL/Index.h>
-#include <LibSQL/Meta.h>
#include <LibSQL/TupleDescriptor.h>
namespace SQL {
diff --git a/Userland/Libraries/LibSQL/Meta.h b/Userland/Libraries/LibSQL/Meta.h
index 071020e934..022f3e2d09 100644
--- a/Userland/Libraries/LibSQL/Meta.h
+++ b/Userland/Libraries/LibSQL/Meta.h
@@ -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>
diff --git a/Userland/Libraries/LibSQL/Serializer.cpp b/Userland/Libraries/LibSQL/Serializer.cpp
index 6600c96a76..ae83dc2c46 100644
--- a/Userland/Libraries/LibSQL/Serializer.cpp
+++ b/Userland/Libraries/LibSQL/Serializer.cpp
@@ -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());
}
diff --git a/Userland/Libraries/LibSQL/Serializer.h b/Userland/Libraries/LibSQL/Serializer.h
index ee250c92ee..8a2be68e3d 100644
--- a/Userland/Libraries/LibSQL/Serializer.h
+++ b/Userland/Libraries/LibSQL/Serializer.h
@@ -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());
diff --git a/Userland/Libraries/LibSQL/TreeNode.cpp b/Userland/Libraries/LibSQL/TreeNode.cpp
index b17da4902c..b4dd4c37a7 100644
--- a/Userland/Libraries/LibSQL/TreeNode.cpp
+++ b/Userland/Libraries/LibSQL/TreeNode.cpp
@@ -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);
- }
}
}
diff --git a/Userland/Libraries/LibSQL/Tuple.cpp b/Userland/Libraries/LibSQL/Tuple.cpp
index 3c92103ac8..03c6b13c56 100644
--- a/Userland/Libraries/LibSQL/Tuple.cpp
+++ b/Userland/Libraries/LibSQL/Tuple.cpp
@@ -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();
}
diff --git a/Userland/Libraries/LibSQL/TupleDescriptor.h b/Userland/Libraries/LibSQL/TupleDescriptor.h
index 26f3410228..2082e7f3da 100644
--- a/Userland/Libraries/LibSQL/TupleDescriptor.h
+++ b/Userland/Libraries/LibSQL/TupleDescriptor.h
@@ -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));
}
diff --git a/Userland/Libraries/LibSQL/Value.cpp b/Userland/Libraries/LibSQL/Value.cpp
index 606fbb878f..8fb9dacd9c 100644
--- a/Userland/Libraries/LibSQL/Value.cpp
+++ b/Userland/Libraries/LibSQL/Value.cpp
@@ -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: