Skip to content

Commit a99c129

Browse files
gmtatrflynn89
authored andcommitted
LibSQL: Clean up code style and remove unused includes
No functional changes.
1 parent 8992ff5 commit a99c129

File tree

14 files changed

+43
-96
lines changed

14 files changed

+43
-96
lines changed

Tests/LibSQL/TestSqlBtreeIndex.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ void insert_into_and_scan_btree(int num_keys)
208208
SQL::Tuple prev;
209209
for (auto iter = btree->begin(); !iter.is_end(); iter++, count++) {
210210
auto key = (*iter);
211-
if (prev.size()) {
211+
if (prev.size())
212212
EXPECT(prev < key);
213-
}
214213
auto key_value = key[0].to_int<i32>();
215214
for (auto ix = 0; ix < num_keys; ix++) {
216215
if (keys[ix] == key_value) {

Userland/Libraries/LibSQL/BTreeIterator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ BTreeIterator BTreeIterator::next() const
133133
// end (which is really the beginning) of the tree.
134134
BTreeIterator BTreeIterator::previous() const
135135
{
136-
if (is_end()) {
136+
if (is_end())
137137
return end();
138-
}
139138

140139
auto node = m_current;
141140
auto ix = m_index;

Userland/Libraries/LibSQL/Database.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
*/
77

88
#include <AK/DeprecatedString.h>
9-
#include <AK/RefPtr.h>
10-
9+
#include <AK/NonnullRefPtr.h>
1110
#include <LibSQL/BTree.h>
1211
#include <LibSQL/Database.h>
1312
#include <LibSQL/Heap.h>
@@ -174,9 +173,8 @@ ErrorOr<Vector<Row>> Database::select_all(TableDef& table)
174173
{
175174
VERIFY(m_table_cache.get(table.key().hash()).has_value());
176175
Vector<Row> ret;
177-
for (auto pointer = table.pointer(); pointer; pointer = ret.last().next_pointer()) {
176+
for (auto pointer = table.pointer(); pointer; pointer = ret.last().next_pointer())
178177
ret.append(m_serializer.deserialize_block<Row>(pointer, table, pointer));
179-
}
180178
return ret;
181179
}
182180

Userland/Libraries/LibSQL/HashIndex.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ void HashBucket::serialize(Serializer& serializer) const
8686
pointer(), index(), local_depth(), size());
8787
serializer.serialize<u32>(local_depth());
8888
serializer.serialize<u32>(size());
89-
for (auto& key : m_entries) {
89+
for (auto& key : m_entries)
9090
serializer.serialize<Key>(key);
91-
}
9291
}
9392

9493
void HashBucket::deserialize(Serializer& serializer)
@@ -111,9 +110,8 @@ void HashBucket::deserialize(Serializer& serializer)
111110
size_t HashBucket::length() const
112111
{
113112
size_t len = 2 * sizeof(u32);
114-
for (auto& key : m_entries) {
113+
for (auto& key : m_entries)
115114
len += key.length();
116-
}
117115
return len;
118116
}
119117

@@ -132,9 +130,8 @@ bool HashBucket::insert(Key const& key)
132130
{
133131
if (!m_inflated)
134132
m_hash_index.serializer().deserialize_block_to(pointer(), *this);
135-
if (find_key_in_bucket(key).has_value()) {
133+
if (find_key_in_bucket(key).has_value())
136134
return false;
137-
}
138135
if ((length() + key.length()) > BLOCKSIZE) {
139136
dbgln_if(SQL_DEBUG, "Adding key {} would make length exceed block size", key.to_deprecated_string());
140137
return false;
@@ -148,9 +145,8 @@ Optional<size_t> HashBucket::find_key_in_bucket(Key const& key)
148145
{
149146
for (auto ix = 0u; ix < size(); ix++) {
150147
auto& k = entries()[ix];
151-
if (k == key) {
148+
if (k == key)
152149
return ix;
153-
}
154150
}
155151
return {};
156152
}
@@ -199,19 +195,17 @@ void HashBucket::list_bucket()
199195
{
200196
warnln("Bucket #{} size {} local depth {} pointer {}{}",
201197
index(), size(), local_depth(), pointer(), (pointer() ? "" : " (VIRTUAL)"));
202-
for (auto& key : entries()) {
198+
for (auto& key : entries())
203199
warnln(" {} hash {}", key.to_deprecated_string(), key.hash());
204-
}
205200
}
206201

207202
HashIndex::HashIndex(Serializer& serializer, NonnullRefPtr<TupleDescriptor> const& descriptor, u32 first_node)
208203
: Index(serializer, descriptor, true, first_node)
209204
, m_nodes()
210205
, m_buckets()
211206
{
212-
if (!first_node) {
207+
if (!first_node)
213208
set_pointer(new_record_pointer());
214-
}
215209
if (serializer.has_block(first_node)) {
216210
u32 pointer = first_node;
217211
do {
@@ -272,9 +266,8 @@ HashBucket* HashIndex::get_bucket_for_insert(Key const& key)
272266
auto moved = 0;
273267
for (auto entry_index = (int)bucket->m_entries.size() - 1; entry_index >= 0; entry_index--) {
274268
if (bucket->m_entries[entry_index].hash() % size() == ix) {
275-
if (!sub_bucket->pointer()) {
269+
if (!sub_bucket->pointer())
276270
sub_bucket->set_pointer(new_record_pointer());
277-
}
278271
sub_bucket->insert(bucket->m_entries.take(entry_index));
279272
moved++;
280273
}
@@ -389,18 +382,12 @@ void HashIndex::list_hash()
389382
{
390383
warnln("Number of buckets: {} (Global depth {})", size(), global_depth());
391384
warn("Directory pointer(s): ");
392-
for (auto ptr : m_nodes) {
385+
for (auto ptr : m_nodes)
393386
warn("{}, ", ptr);
394-
}
395387
warnln();
396388

397-
bool first_bucket = true;
398-
for (auto& bucket : m_buckets) {
399-
if (first_bucket) {
400-
first_bucket = false;
401-
}
389+
for (auto& bucket : m_buckets)
402390
bucket->list_bucket();
403-
}
404391
}
405392

406393
HashIndexIterator::HashIndexIterator(HashBucket const* bucket, size_t index)

Userland/Libraries/LibSQL/Heap.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
#include <LibCore/IODevice.h>
1111
#include <LibCore/System.h>
1212
#include <LibSQL/Heap.h>
13-
#include <LibSQL/Serializer.h>
1413
#include <sys/stat.h>
15-
#include <sys/types.h>
1614

1715
namespace SQL {
1816

@@ -169,9 +167,8 @@ ErrorOr<void> Heap::flush()
169167
{
170168
VERIFY(m_file);
171169
Vector<u32> blocks;
172-
for (auto& wal_entry : m_write_ahead_log) {
170+
for (auto& wal_entry : m_write_ahead_log)
173171
blocks.append(wal_entry.key);
174-
}
175172
quick_sort(blocks);
176173
for (auto& block : blocks) {
177174
auto buffer_it = m_write_ahead_log.find(block);
@@ -221,9 +218,8 @@ ErrorOr<void> Heap::read_zero_block()
221218

222219
memcpy(m_user_values.data(), buffer.offset_pointer(USER_VALUES_OFFSET), m_user_values.size() * sizeof(u32));
223220
for (auto ix = 0u; ix < m_user_values.size(); ix++) {
224-
if (m_user_values[ix]) {
221+
if (m_user_values[ix])
225222
dbgln_if(SQL_DEBUG, "User value {}: {}", ix, m_user_values[ix]);
226-
}
227223
}
228224
return {};
229225
}
@@ -237,9 +233,8 @@ void Heap::update_zero_block()
237233
dbgln_if(SQL_DEBUG, "Table Columns root node: {}", m_table_columns_root);
238234
dbgln_if(SQL_DEBUG, "Free list: {}", m_free_list);
239235
for (auto ix = 0u; ix < m_user_values.size(); ix++) {
240-
if (m_user_values[ix]) {
236+
if (m_user_values[ix])
241237
dbgln_if(SQL_DEBUG, "User value {}: {}", ix, m_user_values[ix]);
242-
}
243238
}
244239

245240
// FIXME: Handle an OOM failure here.
@@ -263,9 +258,8 @@ void Heap::initialize_zero_block()
263258
m_table_columns_root = 0;
264259
m_next_block = 1;
265260
m_free_list = 0;
266-
for (auto& user : m_user_values) {
261+
for (auto& user : m_user_values)
267262
user = 0u;
268-
}
269263
update_zero_block();
270264
}
271265

Userland/Libraries/LibSQL/Heap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <AK/Debug.h>
1111
#include <AK/DeprecatedString.h>
1212
#include <AK/HashMap.h>
13-
#include <AK/Vector.h>
1413
#include <LibCore/File.h>
1514
#include <LibCore/Object.h>
1615

Userland/Libraries/LibSQL/Index.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <LibSQL/Heap.h>
88
#include <LibSQL/Index.h>
9-
#include <LibSQL/Meta.h>
109
#include <LibSQL/TupleDescriptor.h>
1110

1211
namespace SQL {

Userland/Libraries/LibSQL/Meta.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#pragma once
88

99
#include <AK/DeprecatedString.h>
10-
#include <AK/NonnullOwnPtr.h>
1110
#include <AK/NonnullRefPtr.h>
1211
#include <AK/Result.h>
1312
#include <AK/Vector.h>

Userland/Libraries/LibSQL/Serializer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace SQL {
1010

1111
void Serializer::serialize(DeprecatedString const& text)
1212
{
13-
serialize<u32>((u32)text.length());
13+
serialize<u32>(text.length());
1414
if (!text.is_empty())
1515
write((u8 const*)text.characters(), text.length());
1616
}

Userland/Libraries/LibSQL/Serializer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <AK/Debug.h>
1111
#include <AK/DeprecatedString.h>
1212
#include <AK/Format.h>
13-
#include <AK/ScopeGuard.h>
1413
#include <LibSQL/Forward.h>
1514
#include <LibSQL/Heap.h>
1615
#include <string.h>
@@ -155,9 +154,8 @@ class Serializer {
155154
StringBuilder builder;
156155
builder.appendff("{0} {1:04x} | ", prefix, sz);
157156
Vector<DeprecatedString> bytes;
158-
for (auto ix = 0u; ix < sz; ++ix) {
157+
for (auto ix = 0u; ix < sz; ++ix)
159158
bytes.append(DeprecatedString::formatted("{0:02x}", *(ptr + ix)));
160-
}
161159
StringBuilder bytes_builder;
162160
bytes_builder.join(' ', bytes);
163161
builder.append(bytes_builder.to_deprecated_string());

0 commit comments

Comments
 (0)