summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-05-28 11:53:16 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-05-28 17:31:20 +0200
commit0dc9af5f7e26b0dfa42cb75c900b9ef7a2192425 (patch)
tree93dbbbeb714f258bd7fb044633eb83bdcd908286 /AK
parentc11351ac507f863699d78aec46a77bd4d59e743c (diff)
downloadserenity-0dc9af5f7e26b0dfa42cb75c900b9ef7a2192425.zip
Add clang-format file
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
Diffstat (limited to 'AK')
-rw-r--r--AK/AKString.h14
-rw-r--r--AK/Assertions.h13
-rw-r--r--AK/Badge.h2
-rw-r--r--AK/Bitmap.h3
-rw-r--r--AK/ByteBuffer.h52
-rw-r--r--AK/CircularQueue.h8
-rw-r--r--AK/DoublyLinkedList.h64
-rw-r--r--AK/FileSystemPath.cpp4
-rw-r--r--AK/FileSystemPath.h2
-rw-r--r--AK/Function.h10
-rw-r--r--AK/HashFunctions.h1
-rw-r--r--AK/HashMap.h7
-rw-r--r--AK/HashTable.h15
-rw-r--r--AK/InlineLinkedList.h53
-rw-r--r--AK/MappedFile.cpp9
-rw-r--r--AK/MappedFile.h3
-rw-r--r--AK/NetworkOrdered.h3
-rw-r--r--AK/Noncopyable.h4
-rw-r--r--AK/OwnPtr.h30
-rw-r--r--AK/QuickSort.h4
-rw-r--r--AK/RetainPtr.h77
-rw-r--r--AK/Retainable.h15
-rw-r--r--AK/Retained.h159
-rw-r--r--AK/SinglyLinkedList.h58
-rw-r--r--AK/StdLibExtras.cpp50
-rw-r--r--AK/StdLibExtras.h214
-rw-r--r--AK/String.cpp12
-rw-r--r--AK/StringBuilder.cpp8
-rw-r--r--AK/StringBuilder.h3
-rw-r--r--AK/StringImpl.cpp6
-rw-r--r--AK/StringImpl.h28
-rw-r--r--AK/StringView.cpp7
-rw-r--r--AK/StringView.h14
-rw-r--r--AK/TemporaryChange.h7
-rw-r--r--AK/Traits.h6
-rw-r--r--AK/Types.h10
-rw-r--r--AK/Vector.h62
-rw-r--r--AK/WeakPtr.h14
-rw-r--r--AK/Weakable.h17
-rw-r--r--AK/kmalloc.h27
-rw-r--r--AK/printf.cpp135
41 files changed, 818 insertions, 412 deletions
diff --git a/AK/AKString.h b/AK/AKString.h
index 80014ac8e1..b93843b719 100644
--- a/AK/AKString.h
+++ b/AK/AKString.h
@@ -3,18 +3,18 @@
#include <AK/ByteBuffer.h>
#include <AK/RetainPtr.h>
#include <AK/StringImpl.h>
+#include <AK/StringView.h>
#include <AK/Traits.h>
#include <AK/Vector.h>
-#include <AK/StringView.h>
#include <AK/kstdio.h>
namespace AK {
class String {
public:
- ~String() { }
+ ~String() {}
- String() { }
+ String() {}
String(StringView view)
: m_impl(StringImpl::create(view.characters(), view.length()))
@@ -96,7 +96,11 @@ public:
bool is_empty() const { return length() == 0; }
ssize_t length() const { return m_impl ? m_impl->length() : 0; }
const char* characters() const { return m_impl ? m_impl->characters() : nullptr; }
- char operator[](ssize_t i) const { ASSERT(m_impl); return (*m_impl)[i]; }
+ char operator[](ssize_t i) const
+ {
+ ASSERT(m_impl);
+ return (*m_impl)[i];
+ }
bool ends_with(const String&) const;
@@ -131,7 +135,7 @@ public:
static String copy(const BufferType& buffer, ShouldChomp should_chomp = NoChomp)
{
if (buffer.is_null())
- return { };
+ return {};
if (buffer.is_empty())
return empty();
return String((const char*)buffer.data(), buffer.size(), should_chomp);
diff --git a/AK/Assertions.h b/AK/Assertions.h
index bd2404cd68..35c92442b2 100644
--- a/AK/Assertions.h
+++ b/AK/Assertions.h
@@ -1,13 +1,13 @@
#pragma once
#ifdef KERNEL
-#include <Kernel/Assertions.h>
+# include <Kernel/Assertions.h>
#else
-#include <assert.h>
-#ifndef __serenity__
-#define ASSERT assert
-#define ASSERT_NOT_REACHED assert(false)
-#endif
+# include <assert.h>
+# ifndef __serenity__
+# define ASSERT assert
+# define ASSERT_NOT_REACHED assert(false)
+# endif
#endif
namespace AK {
@@ -17,4 +17,3 @@ inline void not_implemented() { ASSERT(false); }
}
using AK::not_implemented;
-
diff --git a/AK/Badge.h b/AK/Badge.h
index 46ae8fbce9..0bcb62de4c 100644
--- a/AK/Badge.h
+++ b/AK/Badge.h
@@ -3,5 +3,5 @@
template<typename T>
class Badge {
friend T;
- Badge() { }
+ Badge() {}
};
diff --git a/AK/Bitmap.h b/AK/Bitmap.h
index ad7c304e0c..1c013cc3c0 100644
--- a/AK/Bitmap.h
+++ b/AK/Bitmap.h
@@ -1,9 +1,9 @@
#pragma once
+#include "Assertions.h"
#include "StdLibExtras.h"
#include "Types.h"
#include "kmalloc.h"
-#include "Assertions.h"
namespace AK {
@@ -77,4 +77,3 @@ private:
}
using AK::Bitmap;
-
diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h
index 45b213713d..c472e94022 100644
--- a/AK/ByteBuffer.h
+++ b/AK/ByteBuffer.h
@@ -1,9 +1,9 @@
#pragma once
-#include "Types.h"
#include "StdLibExtras.h"
-#include <AK/Retainable.h>
+#include "Types.h"
#include <AK/RetainPtr.h>
+#include <AK/Retainable.h>
#include <AK/kmalloc.h>
namespace AK {
@@ -28,8 +28,16 @@ public:
m_data = nullptr;
}
- byte& operator[](int i) { ASSERT(i < m_size); return m_data[i]; }
- const byte& operator[](int i) const { ASSERT(i < m_size); return m_data[i]; }
+ byte& operator[](int i)
+ {
+ ASSERT(i < m_size);
+ return m_data[i];
+ }
+ const byte& operator[](int i) const
+ {
+ ASSERT(i < m_size);
+ return m_data[i];
+ }
bool is_empty() const { return !m_size; }
int size() const { return m_size; }
@@ -52,11 +60,16 @@ public:
void grow(int size);
private:
- enum ConstructionMode { Uninitialized, Copy, Wrap, Adopt };
- explicit ByteBufferImpl(int); // For ConstructionMode=Uninitialized
+ enum ConstructionMode {
+ Uninitialized,
+ Copy,
+ Wrap,
+ Adopt
+ };
+ explicit ByteBufferImpl(int); // For ConstructionMode=Uninitialized
ByteBufferImpl(const void*, int, ConstructionMode); // For ConstructionMode=Copy
- ByteBufferImpl(void*, int, ConstructionMode); // For ConstructionMode=Wrap/Adopt
- ByteBufferImpl() { }
+ ByteBufferImpl(void*, int, ConstructionMode); // For ConstructionMode=Wrap/Adopt
+ ByteBufferImpl() {}
byte* m_data { nullptr };
int m_size { 0 };
@@ -65,8 +78,8 @@ private:
class ByteBuffer {
public:
- ByteBuffer() { }
- ByteBuffer(std::nullptr_t) { }
+ ByteBuffer() {}
+ ByteBuffer(std::nullptr_t) {}
ByteBuffer(const ByteBuffer& other)
: m_impl(other.m_impl.copy_ref())
{
@@ -101,8 +114,16 @@ public:
bool operator!() const { return is_null(); }
bool is_null() const { return m_impl == nullptr; }
- byte& operator[](ssize_t i) { ASSERT(m_impl); return (*m_impl)[i]; }
- byte operator[](ssize_t i) const { ASSERT(m_impl); return (*m_impl)[i]; }
+ byte& operator[](ssize_t i)
+ {
+ ASSERT(m_impl);
+ return (*m_impl)[i];
+ }
+ byte operator[](ssize_t i) const
+ {
+ ASSERT(m_impl);
+ return (*m_impl)[i];
+ }
bool is_empty() const { return !m_impl || m_impl->is_empty(); }
ssize_t size() const { return m_impl ? m_impl->size() : 0; }
@@ -121,7 +142,7 @@ public:
ByteBuffer isolated_copy() const
{
if (!m_impl)
- return { };
+ return {};
return copy(m_impl->pointer(), m_impl->size());
}
@@ -135,9 +156,9 @@ public:
ByteBuffer slice(ssize_t offset, ssize_t size) const
{
if (is_null())
- return { };
+ return {};
if (offset >= this->size())
- return { };
+ return {};
if (offset + size >= this->size())
size = this->size() - offset;
return copy(offset_pointer(offset), size);
@@ -241,4 +262,3 @@ inline Retained<ByteBufferImpl> ByteBufferImpl::adopt(void* data, int size)
}
using AK::ByteBuffer;
-
diff --git a/AK/CircularQueue.h b/AK/CircularQueue.h
index 605402e0c1..7f1ce3ccf9 100644
--- a/AK/CircularQueue.h
+++ b/AK/CircularQueue.h
@@ -60,9 +60,14 @@ public:
}
const T& operator*() const { return m_queue.m_elements[m_index]; }
+
private:
friend class CircularQueue;
- ConstIterator(const CircularQueue& queue, const int index) : m_queue(queue), m_index(index) { }
+ ConstIterator(const CircularQueue& queue, const int index)
+ : m_queue(queue)
+ , m_index(index)
+ {
+ }
const CircularQueue& m_queue;
int m_index { 0 };
};
@@ -82,4 +87,3 @@ private:
}
using AK::CircularQueue;
-
diff --git a/AK/DoublyLinkedList.h b/AK/DoublyLinkedList.h
index 2aa804175b..b3135f6206 100644
--- a/AK/DoublyLinkedList.h
+++ b/AK/DoublyLinkedList.h
@@ -9,22 +9,28 @@ template<typename T>
class DoublyLinkedList {
private:
struct Node {
- explicit Node(const T& v) : value(v) { }
- explicit Node(T&& v) : value(move(v)) { }
+ explicit Node(const T& v)
+ : value(v)
+ {
+ }
+ explicit Node(T&& v)
+ : value(move(v))
+ {
+ }
T value;
Node* next { nullptr };
Node* prev { nullptr };
};
public:
- DoublyLinkedList() { }
+ DoublyLinkedList() {}
~DoublyLinkedList() { clear(); }
bool is_empty() const { return !head(); }
void clear()
{
- for (auto* node = m_head; node; ) {
+ for (auto* node = m_head; node;) {
auto* next = node->next;
delete node;
node = next;
@@ -33,15 +39,30 @@ public:
m_tail = nullptr;
}
- T& first() { ASSERT(head()); return head()->value; }
- const T& first() const { ASSERT(head()); return head()->value; }
- T& last() { ASSERT(head()); return tail()->value; }
- const T& last() const { ASSERT(head()); return tail()->value; }
+ T& first()
+ {
+ ASSERT(head());
+ return head()->value;
+ }
+ const T& first() const
+ {
+ ASSERT(head());
+ return head()->value;
+ }
+ T& last()
+ {
+ ASSERT(head());
+ return tail()->value;
+ }
+ const T& last() const
+ {
+ ASSERT(head());
+ return tail()->value;
+ }
void append(T&& value)
{
append_node(new Node(move(value)));
-
}
void append(const T& value)
@@ -62,14 +83,22 @@ public:
public:
bool operator!=(const Iterator& other) const { return m_node != other.m_node; }
bool operator==(const Iterator& other) const { return m_node == other.m_node; }
- Iterator& operator++() { m_node = m_node->next; return *this; }
+ Iterator& operator++()
+ {
+ m_node = m_node->next;
+ return *this;
+ }
T& operator*() { return m_node->value; }
T* operator->() { return &m_node->value; }
bool is_end() const { return !m_node; }
static Iterator universal_end() { return Iterator(nullptr); }
+
private:
friend class DoublyLinkedList;
- explicit Iterator(DoublyLinkedList::Node* node) : m_node(node) { }
+ explicit Iterator(DoublyLinkedList::Node* node)
+ : m_node(node)
+ {
+ }
DoublyLinkedList::Node* m_node;
};
@@ -80,14 +109,22 @@ public:
public:
bool operator!=(const ConstIterator& other) const { return m_node != other.m_node; }
bool operator==(const ConstIterator& other) const { return m_node == other.m_node; }
- ConstIterator& operator++() { m_node = m_node->next; return *this; }
+ ConstIterator& operator++()
+ {
+ m_node = m_node->next;
+ return *this;
+ }
const T& operator*() const { return m_node->value; }
const T* operator->() const { return &m_node->value; }
bool is_end() const { return !m_node; }
static ConstIterator universal_end() { return ConstIterator(nullptr); }
+
private:
friend class DoublyLinkedList;
- explicit ConstIterator(const DoublyLinkedList::Node* node) : m_node(node) { }
+ explicit ConstIterator(const DoublyLinkedList::Node* node)
+ : m_node(node)
+ {
+ }
const DoublyLinkedList::Node* m_node;
};
@@ -163,4 +200,3 @@ private:
}
using AK::DoublyLinkedList;
-
diff --git a/AK/FileSystemPath.cpp b/AK/FileSystemPath.cpp
index e094c1de3d..07d8d5ea82 100644
--- a/AK/FileSystemPath.cpp
+++ b/AK/FileSystemPath.cpp
@@ -1,7 +1,7 @@
#include "FileSystemPath.h"
+#include "StringBuilder.h"
#include "Vector.h"
#include "kstdio.h"
-#include "StringBuilder.h"
namespace AK {
@@ -14,7 +14,7 @@ FileSystemPath::FileSystemPath(const String& s)
bool FileSystemPath::canonicalize(bool resolve_symbolic_links)
{
// FIXME: Implement "resolve_symbolic_links"
- (void) resolve_symbolic_links;
+ (void)resolve_symbolic_links;
auto parts = m_string.split('/');
Vector<String> canonical_parts;
diff --git a/AK/FileSystemPath.h b/AK/FileSystemPath.h
index 3e56523269..b62160a526 100644
--- a/AK/FileSystemPath.h
+++ b/AK/FileSystemPath.h
@@ -6,7 +6,7 @@ namespace AK {
class FileSystemPath {
public:
- FileSystemPath() { }
+ FileSystemPath() {}
explicit FileSystemPath(const String&);
bool is_valid() const { return m_is_valid; }
diff --git a/AK/Function.h b/AK/Function.h
index b2d10aa0fe..bea6708ca5 100644
--- a/AK/Function.h
+++ b/AK/Function.h
@@ -31,13 +31,14 @@
namespace AK {
-template<typename> class Function;
+template<typename>
+class Function;
-template <typename Out, typename... In>
+template<typename Out, typename... In>
class Function<Out(In...)> {
public:
Function() = default;
- Function(std::nullptr_t) { }
+ Function(std::nullptr_t) {}
template<typename CallableType, class = typename EnableIf<!(IsPointer<CallableType>::value && IsFunction<typename RemovePointer<CallableType>::Type>::value) && IsRvalueReference<CallableType&&>::value>::Type>
Function(CallableType&& callable)
@@ -82,7 +83,7 @@ public:
private:
class CallableWrapperBase {
public:
- virtual ~CallableWrapperBase() { }
+ virtual ~CallableWrapperBase() {}
virtual Out call(In...) const = 0;
};
@@ -109,4 +110,3 @@ private:
}
using AK::Function;
-
diff --git a/AK/HashFunctions.h b/AK/HashFunctions.h
index 21bfaff94e..4155d23c67 100644
--- a/AK/HashFunctions.h
+++ b/AK/HashFunctions.h
@@ -17,4 +17,3 @@ inline unsigned pair_int_hash(dword key1, dword key2)
{
return int_hash((int_hash(key1) * 209) ^ (int_hash(key2 * 413)));
}
-
diff --git a/AK/HashMap.h b/AK/HashMap.h
index 828a9017e1..bd58a5a8e6 100644
--- a/AK/HashMap.h
+++ b/AK/HashMap.h
@@ -32,7 +32,7 @@ private:
};
public:
- HashMap() { }
+ HashMap() {}
HashMap(HashMap&& other)
: m_table(move(other.m_table))
@@ -115,13 +115,13 @@ private:
template<typename K, typename V>
void HashMap<K, V>::set(const K& key, V&& value)
{
- m_table.set(Entry{key, move(value)});
+ m_table.set(Entry { key, move(value) });
}
template<typename K, typename V>
void HashMap<K, V>::set(const K& key, const V& value)
{
- m_table.set(Entry{key, value});
+ m_table.set(Entry { key, value });
}
template<typename K, typename V>
@@ -148,4 +148,3 @@ auto HashMap<K, V>::find(const K& key) const -> ConstIteratorType
}
using AK::HashMap;
-
diff --git a/AK/HashTable.h b/AK/HashTable.h
index 8a4b5f847d..7720a38f86 100644
--- a/AK/HashTable.h
+++ b/AK/HashTable.h
@@ -2,15 +2,16 @@
#include "Assertions.h"
#include "DoublyLinkedList.h"
-#include "Traits.h"
#include "StdLibExtras.h"
+#include "Traits.h"
#include "kstdio.h"
//#define HASHTABLE_DEBUG
namespace AK {
-template<typename T, typename = Traits<T>> class HashTable;
+template<typename T, typename = Traits<T>>
+class HashTable;
template<typename T, typename TraitsForT>
class HashTable {
@@ -20,7 +21,7 @@ private:
};
public:
- HashTable() { }
+ HashTable() {}
explicit HashTable(HashTable&& other)
: m_buckets(other.m_buckets)
, m_size(other.m_size)
@@ -112,6 +113,7 @@ public:
return;
}
}
+
private:
friend class HashTable;
explicit Iterator(HashTable& table, bool is_end, typename DoublyLinkedList<T>::Iterator bucket_iterator = DoublyLinkedList<T>::Iterator::universal_end(), int bucket_index = 0)
@@ -190,6 +192,7 @@ public:
return;
}
}
+
private:
friend class HashTable;
ConstIterator(const HashTable& table, bool is_end, typename DoublyLinkedList<T>::ConstIterator bucket_iterator = DoublyLinkedList<T>::ConstIterator::universal_end(), int bucket_index = 0)
@@ -285,7 +288,6 @@ void HashTable<T, TraitsForT>::set(const T& value)
m_size++;
}
-
template<typename T, typename TraitsForT>
void HashTable<T, TraitsForT>::rehash(int new_capacity)
{
@@ -308,14 +310,14 @@ void HashTable<T, TraitsForT>::rehash(int new_capacity)
}
}
- delete [] old_buckets;
+ delete[] old_buckets;
}
template<typename T, typename TraitsForT>
void HashTable<T, TraitsForT>::clear()
{
if (m_buckets) {
- delete [] m_buckets;
+ delete[] m_buckets;
m_buckets = nullptr;
}
m_capacity = 0;
@@ -429,4 +431,3 @@ void HashTable<T, TraitsForT>::dump() const
}
using AK::HashTable;
-
diff --git a/AK/InlineLinkedList.h b/AK/InlineLinkedList.h
index a6156c4284..08e4fbdb26 100644
--- a/AK/InlineLinkedList.h
+++ b/AK/InlineLinkedList.h
@@ -5,47 +5,54 @@
namespace AK {
-template<typename T> class InlineLinkedListNode {
+template<typename T>
+class InlineLinkedListNode {
public:
InlineLinkedListNode();
-
+
void set_prev(T*);
void set_next(T*);
-
+
T* prev() const;
T* next() const;
};
-template<typename T> inline InlineLinkedListNode<T>::InlineLinkedListNode()
+template<typename T>
+inline InlineLinkedListNode<T>::InlineLinkedListNode()
{
set_prev(0);
set_next(0);
}
-template<typename T> inline void InlineLinkedListNode<T>::set_prev(T* prev)
+template<typename T>
+inline void InlineLinkedListNode<T>::set_prev(T* prev)
{
static_cast<T*>(this)->m_prev = prev;
}
-template<typename T> inline void InlineLinkedListNode<T>::set_next(T* next)
+template<typename T>
+inline void InlineLinkedListNode<T>::set_next(T* next)
{
static_cast<T*>(this)->m_next = next;
}
-template<typename T> inline T* InlineLinkedListNode<T>::prev() const
+template<typename T>
+inline T* InlineLinkedListNode<T>::prev() const
{
return static_cast<const T*>(this)->m_prev;
}
-template<typename T> inline T* InlineLinkedListNode<T>::next() const
+template<typename T>
+inline T* InlineLinkedListNode<T>::next() const
{
return static_cast<const T*>(this)->m_next;
}
-template<typename T> class InlineLinkedList {
+template<typename T>
+class InlineLinkedList {
public:
- InlineLinkedList() { }
-
+ InlineLinkedList() {}
+
bool is_empty() const { return !m_head; }
size_t size_slow() const;
void clear();
@@ -75,7 +82,8 @@ private:
T* m_tail { nullptr };
};
-template<typename T> inline size_t InlineLinkedList<T>::size_slow() const
+template<typename T>
+inline size_t InlineLinkedList<T>::size_slow() const
{
size_t size = 0;
for (T* node = m_head; node; node = node->next())
@@ -83,13 +91,15 @@ template<typename T> inline size_t InlineLinkedList<T>::size_slow() const
return size;
}
-template<typename T> inline void InlineLinkedList<T>::clear()
+template<typename T>
+inline void InlineLinkedList<T>::clear()
{
m_head = 0;
m_tail = 0;
}
-template<typename T> inline void InlineLinkedList<T>::prepend(T* node)
+template<typename T>
+inline void InlineLinkedList<T>::prepend(T* node)
{
if (!m_head) {
ASSERT(!m_tail);
@@ -107,7 +117,8 @@ template<typename T> inline void InlineLinkedList<T>::prepend(T* node)
m_head = node;
}
-template<typename T> inline void InlineLinkedList<T>::append(T* node)
+template<typename T>
+inline void InlineLinkedList<T>::append(T* node)
{
if (!m_tail) {
ASSERT(!m_head);
@@ -125,7 +136,8 @@ template<typename T> inline void InlineLinkedList<T>::append(T* node)
m_tail = node;
}
-template<typename T> inline void InlineLinkedList<T>::remove(T* node)
+template<typename T>
+inline void InlineLinkedList<T>::remove(T* node)
{
if (node->prev()) {
ASSERT(node != m_head);
@@ -144,7 +156,8 @@ template<typename T> inline void InlineLinkedList<T>::remove(T* node)
}
}
-template<typename T> inline T* InlineLinkedList<T>::remove_head()
+template<typename T>
+inline T* InlineLinkedList<T>::remove_head()
{
T* node = head();
if (node)
@@ -152,7 +165,8 @@ template<typename T> inline T* InlineLinkedList<T>::remove_head()
return node;
}
-template<typename T> inline T* InlineLinkedList<T>::remove_tail()
+template<typename T>
+inline T* InlineLinkedList<T>::remove_tail()
{
T* node = tail();
if (node)
@@ -160,7 +174,8 @@ template<typename T> inline T* InlineLinkedList<T>::remove_tail()
return node;
}
-template<typename T> inline void InlineLinkedList<T>::append(InlineLinkedList<T>& other)
+template<typename T>
+inline void InlineLinkedList<T>::append(InlineLinkedList<T>& other)
{
if (!other.head())
return;
diff --git a/AK/MappedFile.cpp b/AK/MappedFile.cpp
index a65f76b9ab..b234fa19c6 100644
--- a/AK/MappedFile.cpp
+++ b/AK/MappedFile.cpp
@@ -1,9 +1,9 @@
#include <AK/MappedFile.h>
+#include <fcntl.h>
+#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
-#include <fcntl.h>
#include <unistd.h>
-#include <stdio.h>
//#define DEBUG_MAPPED_FILE
@@ -14,7 +14,7 @@ MappedFile::MappedFile(const String& file_name)
{
m_size = PAGE_SIZE;
m_fd = open(m_file_name.characters(), O_RDONLY | O_CLOEXEC);
-
+
if (m_fd != -1) {
struct stat st;
fstat(m_fd, &st);
@@ -44,7 +44,7 @@ void MappedFile::unmap()
ASSERT(rc == 0);
rc = close(m_fd);
ASSERT(rc == 0);
- m_file_name = { };
+ m_file_name = {};
m_size = 0;
m_fd = -1;
m_map = (void*)-1;
@@ -74,4 +74,3 @@ MappedFile& MappedFile::operator=(MappedFile&& other)
}
}
-
diff --git a/AK/MappedFile.h b/AK/MappedFile.h
index 0398bff7bd..513fd28e5e 100644
--- a/AK/MappedFile.h
+++ b/AK/MappedFile.h
@@ -6,7 +6,7 @@ namespace AK {
class MappedFile {
public:
- MappedFile() { }
+ MappedFile() {}
explicit MappedFile(const String& file_name);
MappedFile(MappedFile&&);
~MappedFile();
@@ -30,4 +30,3 @@ private:
}
using AK::MappedFile;
-
diff --git a/AK/NetworkOrdered.h b/AK/NetworkOrdered.h
index 22805bdf50..4c5aa273cd 100644
--- a/AK/NetworkOrdered.h
+++ b/AK/NetworkOrdered.h
@@ -18,7 +18,8 @@ template<typename T>
}
template<typename T>
-class [[gnu::packed]] NetworkOrdered {
+class [[gnu::packed]] NetworkOrdered
+{
public:
NetworkOrdered()
: m_network_value(0)
diff --git a/AK/Noncopyable.h b/AK/Noncopyable.h
index ff7df2346b..2e2b9d0cbc 100644
--- a/AK/Noncopyable.h
+++ b/AK/Noncopyable.h
@@ -1,6 +1,6 @@
#pragma once
#define AK_MAKE_NONCOPYABLE(c) \
-private: \
- c(const c&) = delete; \
+private: \
+ c(const c&) = delete; \
c& operator=(const c&) = delete;
diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h
index 828aca3110..64168e8596 100644
--- a/AK/OwnPtr.h
+++ b/AK/OwnPtr.h
@@ -1,24 +1,34 @@
#pragma once
#include "StdLibExtras.h"
-#include "Types.h"
#include "Traits.h"
+#include "Types.h"
namespace AK {
template<typename T>
class OwnPtr {
public:
- OwnPtr() { }
- explicit OwnPtr(T* ptr) : m_ptr(ptr) { }
- OwnPtr(OwnPtr&& other) : m_ptr(other.leak_ptr()) { }
- template<typename U> OwnPtr(OwnPtr<U>&& other) : m_ptr(static_cast<T*>(other.leak_ptr())) { }
- OwnPtr(std::nullptr_t) { };
+ OwnPtr() {}
+ explicit OwnPtr(T* ptr)
+ : m_ptr(ptr)
+ {
+ }
+ OwnPtr(OwnPtr&& other)
+ : m_ptr(other.leak_ptr())
+ {
+ }
+ template<typename U>
+ OwnPtr(OwnPtr<U>&& other)
+ : m_ptr(static_cast<T*>(other.leak_ptr()))
+ {
+ }
+ OwnPtr(std::nullptr_t) {};
~OwnPtr()
{
clear();
#ifdef SANITIZE_PTRS
- if constexpr(sizeof(T*) == 8)
+ if constexpr (sizeof(T*) == 8)
m_ptr = (T*)(0xe1e1e1e1e1e1e1e1);
else
m_ptr = (T*)(0xe1e1e1e1);
@@ -91,7 +101,8 @@ private:
T* m_ptr = nullptr;
};
-template<class T, class... Args> inline OwnPtr<T>
+template<class T, class... Args>
+inline OwnPtr<T>
make(Args&&... args)
{
return OwnPtr<T>(new T(AK::forward<Args>(args)...));
@@ -105,6 +116,5 @@ struct Traits<OwnPtr<T>> {
}
-using AK::OwnPtr;
using AK::make;
-
+using AK::OwnPtr;
diff --git a/AK/QuickSort.h b/AK/QuickSort.h
index 790c25786c..2d196d2977 100644
--- a/AK/QuickSort.h
+++ b/AK/QuickSort.h
@@ -8,7 +8,7 @@ bool is_less_than(const T& a, const T& b)
return a < b;
}
-template <typename Iterator, typename LessThan>
+template<typename Iterator, typename LessThan>
void quick_sort(Iterator start, Iterator end, LessThan less_than = is_less_than)
{
int size = end - start;
@@ -24,7 +24,7 @@ void quick_sort(Iterator start, Iterator end, LessThan less_than = is_less_than)
int i = 1;
for (int j = 1; j < size; ++j) {
if (less_than(*(start + j), pivot)) {
- swap(*(start+j), *(start + i));
+ swap(*(start + j), *(start + i));
++i;
}
}
diff --git a/AK/RetainPtr.h b/AK/RetainPtr.h
index d7140ab1c7..0044202dee 100644
--- a/AK/RetainPtr.h
+++ b/AK/RetainPtr.h
@@ -1,38 +1,80 @@
#pragma once
-#include <AK/Types.h>
#include <AK/Retained.h>
+#include <AK/Types.h>
namespace AK {
template<typename T>
class RetainPtr {
public:
- enum AdoptTag { Adopt };
-
- RetainPtr() { }
- RetainPtr(const T* ptr) : m_ptr(const_cast<T*>(ptr)) { retain_if_not_null(m_ptr); }
- RetainPtr(T* ptr) : m_ptr(ptr) { retain_if_not_null(m_ptr); }
- RetainPtr(T& object) : m_ptr(&object) { m_ptr->retain(); }
- RetainPtr(const T& object) : m_ptr(const_cast<T*>(&object)) { m_ptr->retain(); }
- RetainPtr(AdoptTag, T& object) : m_ptr(&object) { }
- RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { }
- RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { }
- template<typename U> RetainPtr(Retained<U>&& other) : m_ptr(static_cast<T*>(&other.leak_ref())) { }
- template<typename U> RetainPtr(RetainPtr<U>&& other) : m_ptr(static_cast<T*>(other.leak_ref())) { }
- RetainPtr(const RetainPtr& other) : m_ptr(const_cast<RetainPtr&>(other).copy_ref().leak_ref()) { }
- template<typename U> RetainPtr(const RetainPtr<U>& other) : m_ptr(const_cast<RetainPtr<U>&>(other).copy_ref().leak_ref()) { }
+ enum AdoptTag {
+ Adopt
+ };
+
+ RetainPtr() {}
+ RetainPtr(const T* ptr)
+ : m_ptr(const_cast<T*>(ptr))
+ {
+ retain_if_not_null(m_ptr);
+ }
+ RetainPtr(T* ptr)
+ : m_ptr(ptr)
+ {
+ retain_if_not_null(m_ptr);
+ }
+ RetainPtr(T& object)
+ : m_ptr(&object)
+ {
+ m_ptr->retain();
+ }
+ RetainPtr(const T& object)
+ : m_ptr(const_cast<T*>(&object))
+ {
+ m_ptr->retain();
+ }
+ RetainPtr(AdoptTag, T& object)
+ : m_ptr(&object)
+ {
+ }
+ RetainPtr(RetainPtr& other)
+ : m_ptr(other.copy_ref().leak_ref())
+ {
+ }
+ RetainPtr(RetainPtr&& other)
+ : m_ptr(other.leak_ref())
+ {
+ }
+ template<typename U>
+ RetainPtr(Retained<U>&& other)
+ : m_ptr(static_cast<T*>(&other.leak_ref()))
+ {
+ }
+ template<typename U>
+ RetainPtr(RetainPtr<U>&& other)
+ : m_ptr(static_cast<T*>(other.leak_ref()))
+ {
+ }
+ RetainPtr(const RetainPtr& other)
+ : m_ptr(const_cast<RetainPtr&>(other).copy_ref().leak_ref())
+ {
+ }
+ template<typename U>
+ RetainPtr(const RetainPtr<U>& other)
+ : m_ptr(const_cast<RetainPtr<U>&>(other).copy_ref().leak_ref())
+ {
+ }
~RetainPtr()
{
clear();
#ifdef SANITIZE_PTRS
- if constexpr(sizeof(T*) == 8)
+ if constexpr (sizeof(T*) == 8)
m_ptr = (T*)(0xe0e0e0e0e0e0e0e0);
else
m_ptr = (T*)(0xe0e0e0e0);
#endif
}
- RetainPtr(std::nullptr_t) { }
+ RetainPtr(std::nullptr_t) {}
RetainPtr& operator=(RetainPtr&& other)
{
@@ -143,4 +185,3 @@ private:
}
using AK::RetainPtr;
-
diff --git a/AK/Retainable.h b/AK/Retainable.h
index fb6a06c4ad..be928f8521 100644
--- a/AK/Retainable.h
+++ b/AK/Retainable.h
@@ -6,27 +6,27 @@
namespace AK {
template<class T>
-constexpr auto call_will_be_destroyed_if_present(T* object) -> decltype(object->will_be_destroyed(), TrueType { })
+constexpr auto call_will_be_destroyed_if_present(T* object) -> decltype(object->will_be_destroyed(), TrueType {})
{
object->will_be_destroyed();
- return { };
+ return {};
}
constexpr auto call_will_be_destroyed_if_present(...) -> FalseType
{
- return { };
+ return {};
}
template<class T>
-constexpr auto call_one_retain_left_if_present(T* object) -> decltype(object->one_retain_left(), TrueType { })
+constexpr auto call_one_retain_left_if_present(T* object) -> decltype(object->one_retain_left(), TrueType {})
{
object->one_retain_left();
- return { };
+ return {};
}
constexpr auto call_one_retain_left_if_present(...) -> FalseType
{
- return { };
+ return {};
}
class RetainableBase {
@@ -43,7 +43,7 @@ public:
}
protected:
- RetainableBase() { }
+ RetainableBase() {}
~RetainableBase()
{
ASSERT(!m_retain_count);
@@ -76,4 +76,3 @@ public:
}
using AK::Retainable;
-
diff --git a/AK/Retained.h b/AK/Retained.h
index f583576c42..e1aa22f8ec 100644
--- a/AK/Retained.h
+++ b/AK/Retained.h
@@ -4,15 +4,15 @@
#include <AK/Types.h>
#ifdef __clang__
-#define CONSUMABLE(initial_state) __attribute__((consumable(initial_state)))
-#define CALLABLE_WHEN(...) __attribute__((callable_when(__VA_ARGS__)))
-#define SET_TYPESTATE(state) __attribute__((set_typestate(state)))
-#define RETURN_TYPESTATE(state) __attribute__((return_typestate(state)))
+# define CONSUMABLE(initial_state) __attribute__((consumable(initial_state)))
+# define CALLABLE_WHEN(...) __attribute__((callable_when(__VA_ARGS__)))
+# define SET_TYPESTATE(state) __attribute__((set_typestate(state)))
+# define RETURN_TYPESTATE(state) __attribute__((return_typestate(state)))
#else
-#define CONSUMABLE(initial_state)
-#define CALLABLE_WHEN(state)
-#define SET_TYPESTATE(state)
-#define RETURN_TYPESTATE(state)
+# define CONSUMABLE(initial_state)
+# define CALLABLE_WHEN(state)
+# define SET_TYPESTATE(state)
+# define RETURN_TYPESTATE(state)
#endif
namespace AK {
@@ -34,30 +34,75 @@ inline void release_if_not_null(T* ptr)
template<typename T>
class CONSUMABLE(unconsumed) Retained {
public:
- enum AdoptTag { Adopt };
-
- RETURN_TYPESTATE(unconsumed) Retained(const T& object) : m_ptr(const_cast<T*>(&object)) { m_ptr->retain(); }
- RETURN_TYPESTATE(unconsumed) Retained(T& object) : m_ptr(&object) { m_ptr->retain(); }
- template<typename U> RETURN_TYPESTATE(unconsumed) Retained(U& object) : m_ptr(&static_cast<T&>(object)) { m_ptr->retain(); }
- RETURN_TYPESTATE(unconsumed) Retained(AdoptTag, T& object) : m_ptr(&object) { }
- RETURN_TYPESTATE(unconsumed) Retained(Retained& other) : m_ptr(&other.copy_ref().leak_ref()) { }
- RETURN_TYPESTATE(unconsumed) Retained(Retained&& other) : m_ptr(&other.leak_ref()) { }
- template<typename U> RETURN_TYPESTATE(unconsumed) Retained(Retained<U>&& other) : m_ptr(static_cast<T*>(&other.leak_ref())) { }
- RETURN_TYPESTATE(unconsumed) Retained(const Retained& other) : m_ptr(&const_cast<Retained&>(other).copy_ref().leak_ref()) { }
- template<typename U> RETURN_TYPESTATE(unconsumed) Retained(const Retained<U>& other) : m_ptr(&const_cast<Retained<U>&>(other).copy_ref().leak_ref()) { }
+ enum AdoptTag {
+ Adopt
+ };
+
+ RETURN_TYPESTATE(unconsumed)
+ Retained(const T& object)
+ : m_ptr(const_cast<T*>(&object))
+ {
+ m_ptr->retain();
+ }
+ RETURN_TYPESTATE(unconsumed)
+ Retained(T& object)
+ : m_ptr(&object)
+ {
+ m_ptr->retain();
+ }
+ template<typename U>
+ RETURN_TYPESTATE(unconsumed)
+ Retained(U& object)
+ : m_ptr(&static_cast<T&>(object))
+ {
+ m_ptr->retain();
+ }
+ RETURN_TYPESTATE(unconsumed)
+ Retained(AdoptTag, T& object)
+ : m_ptr(&object)
+ {
+ }
+ RETURN_TYPESTATE(unconsumed)
+ Retained(Retained& other)
+ : m_ptr(&other.copy_ref().leak_ref())
+ {
+ }
+ RETURN_TYPESTATE(unconsumed)
+ Retained(Retained&& other)
+ : m_ptr(&other.leak_ref())
+ {
+ }
+ template<typename U>
+ RETURN_TYPESTATE(unconsumed)
+ Retained(Retained<U>&& other)
+ : m_ptr(static_cast<T*>(&other.leak_ref()))
+ {
+ }
+ RETURN_TYPESTATE(unconsumed)
+ Retained(const Retained& other)
+ : m_ptr(&const_cast<Retained&>(other).copy_ref().leak_ref())
+ {
+ }
+ template<typename U>
+ RETURN_TYPESTATE(unconsumed)
+ Retained(const Retained<U>& other)
+ : m_ptr(&const_cast<Retained<U>&>(other).copy_ref().leak_ref())
+ {
+ }
~Retained()
{
release_if_not_null(m_ptr);
m_ptr = nullptr;
#ifdef SANITIZE_PTRS
- if constexpr(sizeof(T*) == 8)
+ if constexpr (sizeof(T*) == 8)
m_ptr = (T*)(0xb0b0b0b0b0b0b0b0);
else
m_ptr = (T*)(0xb0b0b0b0);
#endif
}
- CALLABLE_WHEN(unconsumed) Retained& operator=(Retained&& other)
+ CALLABLE_WHEN(unconsumed)
+ Retained& operator=(Retained&& other)
{
if (this != &other) {
release_if_not_null(m_ptr);
@@ -67,7 +112,8 @@ public:
}
template<typename U>
- CALLABLE_WHEN(unconsumed) Retained& operator=(Retained<U>&& other)
+ CALLABLE_WHEN(unconsumed)
+ Retained& operator=(Retained<U>&& other)
{
if (this != static_cast<void*>(&other)) {
release_if_not_null(m_ptr);
@@ -76,7 +122,8 @@ public:
return *this;
}
- CALLABLE_WHEN(unconsumed) Retained& operator=(T& object)
+ CALLABLE_WHEN(unconsumed)
+ Retained& operator=(T& object)
{
if (m_ptr != &object)
release_if_not_null(m_ptr);
@@ -85,12 +132,14 @@ public:
return *this;
}
- CALLABLE_WHEN(unconsumed) Retained copy_ref() const
+ CALLABLE_WHEN(unconsumed)
+ Retained copy_ref() const
{
return Retained(*m_ptr);
}
- CALLABLE_WHEN(unconsumed) SET_TYPESTATE(consumed)
+ CALLABLE_WHEN(unconsumed)
+ SET_TYPESTATE(consumed)
T& leak_ref()
{
ASSERT(m_ptr);
@@ -99,20 +148,60 @@ public:
return *leakedPtr;
}
- CALLABLE_WHEN(unconsumed) T* ptr() { ASSERT(m_ptr); return m_ptr; }
- CALLABLE_WHEN(unconsumed) const T* ptr() const { ASSERT(m_ptr); return m_ptr; }
+ CALLABLE_WHEN(unconsumed)
+ T* ptr()
+ {
+ ASSERT(m_ptr);
+ return m_ptr;
+ }
+ CALLABLE_WHEN(unconsumed)
+ const T* ptr() const
+ {
+ ASSERT(m_ptr);
+ return m_ptr;
+ }
- CALLABLE_WHEN(unconsumed) T* operator->() { ASSERT(m_ptr); return m_ptr; }
- CALLABLE_WHEN(unconsumed) const T* operator->() const { ASSERT(m_ptr); return m_ptr; }
+ CALLABLE_WHEN(unconsumed)
+ T* operator->()
+ {
+ ASSERT(m_ptr);
+ return m_ptr;
+ }
+ CALLABLE_WHEN(unconsumed)
+ const T* operator->() const
+ {
+ ASSERT(m_ptr);
+ return m_ptr;
+ }
- CALLABLE_WHEN(unconsumed) T& operator*() { ASSERT(m_ptr); return *m_ptr; }
- CALLABLE_WHEN(unconsumed) const T& operator*() const { ASSERT(m_ptr); return *m_ptr; }
+ CALLABLE_WHEN(unconsumed)
+ T& operator*()
+ {
+ ASSERT(m_ptr);
+ return *m_ptr;
+ }
+ CALLABLE_WHEN(unconsumed)
+ const T& operator*() const
+ {
+ ASSERT(m_ptr);
+ return *m_ptr;
+ }
- CALLABLE_WHEN(unconsumed) operator T*() { ASSERT(m_ptr); return m_ptr; }
- CALLABLE_WHEN(unconsumed) operator const T*() const { ASSERT(m_ptr); return m_ptr; }
+ CALLABLE_WHEN(unconsumed)
+ operator T*()
+ {
+ ASSERT(m_ptr);
+ return m_ptr;
+ }
+ CALLABLE_WHEN(unconsumed)
+ operator const T*() const
+ {
+ ASSERT(m_ptr);
+ return m_ptr;
+ }
private:
- Retained() { }
+ Retained() {}
T* m_ptr { nullptr };
};
@@ -125,5 +214,5 @@ inline Retained<T> adopt(T& object)
}
-using AK::Retained;
using AK::adopt;
+using AK::Retained;
diff --git a/AK/SinglyLinkedList.h b/AK/SinglyLinkedList.h
index 022b6f9571..c14fe97b45 100644
--- a/AK/SinglyLinkedList.h
+++ b/AK/SinglyLinkedList.h
@@ -8,13 +8,16 @@ template<typename T>
class SinglyLinkedList {
private:
struct Node {
- explicit Node(T&& v) : value(v) { }
+ explicit Node(T&& v)
+ : value(v)
+ {
+ }
T value;
Node* next { nullptr };
};
public:
- SinglyLinkedList() { }
+ SinglyLinkedList() {}
~SinglyLinkedList() { clear(); }
bool is_empty() const { return !head(); }
@@ -29,7 +32,7 @@ public:
void clear()
{
- for (auto* node = m_head; node; ) {
+ for (auto* node = m_head; node;) {
auto* next = node->next;
delete node;
node = next;
@@ -38,10 +41,26 @@ public:
m_tail = nullptr;
}
- T& first() { ASSERT(head()); return head()->value; }
- const T& first() const { ASSERT(head()); return head()->value; }
- T& last() { ASSERT(head()); return tail()->value; }
- const T& last() const { ASSERT(head()); return tail()->value; }
+ T& first()
+ {
+ ASSERT(head());
+ return head()->value;
+ }
+ const T& first() const
+ {
+ ASSERT(head());
+ return head()->value;
+ }
+ T& last()
+ {
+ ASSERT(head());
+ return tail()->value;
+ }
+ const T& last() const
+ {
+ ASSERT(head());
+ return tail()->value;
+ }
T take_first()
{
@@ -79,13 +98,21 @@ public:
class Iterator {
public:
bool operator!=(const Iterator& other) { return m_node != other.m_node; }
- Iterator& operator++() { m_node = m_node->next; return *this; }
+ Iterator& operator++()
+ {
+ m_node = m_node->next;
+ return *this;
+ }
T& operator*() { return m_node->value; }
bool is_end() const { return !m_node; }
static Iterator universal_end() { return Iterator(nullptr); }
+
private:
friend class SinglyLinkedList;
- explicit Iterator(SinglyLinkedList::Node* node) : m_node(node) { }
+ explicit Iterator(SinglyLinkedList::Node* node)
+ : m_node(node)
+ {
+ }
SinglyLinkedList::Node* m_node;
};
@@ -95,13 +122,21 @@ public:
class ConstIterator {
public:
bool operator!=(const ConstIterator& other) { return m_node != other.m_node; }
- ConstIterator& operator++() { m_node = m_node->next; return *this; }
+ ConstIterator& operator++()
+ {
+ m_node = m_node->next;
+ return *this;
+ }
const T& operator*() const { return m_node->value; }
bool is_end() const { return !m_node; }
static ConstIterator universal_end() { return ConstIterator(nullptr); }
+
private:
friend class SinglyLinkedList;
- explicit ConstIterator(const SinglyLinkedList::Node* node) : m_node(node) { }
+ explicit ConstIterator(const SinglyLinkedList::Node* node)
+ : m_node(node)
+ {
+ }
const SinglyLinkedList::Node* m_node;
};
@@ -142,4 +177,3 @@ private:
}
using AK::SinglyLinkedList;
-
diff --git a/AK/StdLibExtras.cpp b/AK/StdLibExtras.cpp
index ee8aa862d9..491fe645ed 100644
--- a/AK/StdLibExtras.cpp
+++ b/AK/StdLibExtras.cpp
@@ -1,5 +1,5 @@
-#include <AK/StdLibExtras.h>
#include <AK/Assertions.h>
+#include <AK/StdLibExtras.h>
#include <AK/Types.h>
#include <AK/kstdio.h>
@@ -20,32 +20,33 @@ void* mmx_memcpy(void* dest, const void* src, size_t len)
"rep movsb\n"
: "=S"(src_ptr), "=D"(dest_ptr), "=c"(prologue)
: "0"(src_ptr), "1"(dest_ptr), "2"(prologue)
- : "memory"
- );
+ : "memory");
}
for (dword i = len / 64; i; --i) {
asm volatile(
- "movq (%0), %%mm0\n"
- "movq 8(%0), %%mm1\n"
- "movq 16(%0), %%mm2\n"
- "movq 24(%0), %%mm3\n"
- "movq 32(%0), %%mm4\n"
- "movq 40(%0), %%mm5\n"
- "movq 48(%0), %%mm6\n"
- "movq 56(%0), %%mm7\n"
- "movq %%mm0, (%1)\n"
- "movq %%mm1, 8(%1)\n"
- "movq %%mm2, 16(%1)\n"
- "movq %%mm3, 24(%1)\n"
- "movq %%mm4, 32(%1)\n"
- "movq %%mm5, 40(%1)\n"
- "movq %%mm6, 48(%1)\n"
- "movq %%mm7, 56(%1)\n"
- :: "r" (src_ptr), "r" (dest_ptr) : "memory");
+ "movq (%0), %%mm0\n"
+ "movq 8(%0), %%mm1\n"
+ "movq 16(%0), %%mm2\n"
+ "movq 24(%0), %%mm3\n"
+ "movq 32(%0), %%mm4\n"
+ "movq 40(%0), %%mm5\n"
+ "movq 48(%0), %%mm6\n"
+ "movq 56(%0), %%mm7\n"
+ "movq %%mm0, (%1)\n"
+ "movq %%mm1, 8(%1)\n"
+ "movq %%mm2, 16(%1)\n"
+ "movq %%mm3, 24(%1)\n"
+ "movq %%mm4, 32(%1)\n"
+ "movq %%mm5, 40(%1)\n"
+ "movq %%mm6, 48(%1)\n"
+ "movq %%mm7, 56(%1)\n" ::"r"(src_ptr),
+ "r"(dest_ptr)
+ : "memory");
src_ptr += 64;
dest_ptr += 64;
}
- asm volatile("emms":::"memory");
+ asm volatile("emms" ::
+ : "memory");
// Whatever remains we'll have to memcpy.
len %= 64;
if (len)
@@ -62,13 +63,15 @@ static inline uint32_t divq(uint64_t n, uint32_t d)
uint32_t n0 = n;
uint32_t q;
uint32_t r;
- asm volatile("divl %4" : "=d"(r), "=a"(q) : "0"(n1), "1"(n0), "rm"(d));
+ asm volatile("divl %4"
+ : "=d"(r), "=a"(q)
+ : "0"(n1), "1"(n0), "rm"(d));
return q;
}
static uint64_t unsigned_divide64(uint64_t n, uint64_t d)
{
- if ((d >> 32) == 0) {
+ if ((d >> 32) == 0) {
uint64_t b = 1ULL << 32;
uint32_t n1 = n >> 32;
uint32_t n0 = n;
@@ -149,5 +152,4 @@ uint64_t __udivmoddi4(uint64_t n, uint64_t d, uint64_t* r)
return q;
}
#endif
-
}
diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h
index d090ad861d..f233ab4219 100644
--- a/AK/StdLibExtras.h
+++ b/AK/StdLibExtras.h
@@ -1,10 +1,10 @@
#pragma once
#ifdef KERNEL
-#include <Kernel/StdLib.h>
+# include <Kernel/StdLib.h>
#else
-#include <stdlib.h>
-#include <string.h>
+# include <stdlib.h>
+# include <string.h>
#endif
#define UNUSED_PARAM(x) (void)x
@@ -27,8 +27,7 @@ extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
"rep movsl\n"
: "=S"(src), "=D"(dest), "=c"(count)
: "S"(src), "D"(dest), "c"(count)
- : "memory"
- );
+ : "memory");
}
[[gnu::always_inline]] inline void fast_dword_fill(dword* dest, dword value, size_t count)
@@ -37,13 +36,12 @@ extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
"rep stosl\n"
: "=D"(dest), "=c"(count)
: "D"(dest), "c"(count), "a"(value)
- : "memory"
- );
+ : "memory");
}
inline constexpr dword round_up_to_power_of_two(dword value, dword power_of_two)
{
- return ((value - 1) & ~ (power_of_two - 1)) + power_of_two;
+ return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
}
namespace AK {
@@ -60,7 +58,6 @@ inline T max(const T& a, const T& b)
return a < b ? b : a;
}
-
template<typename T, typename U>
static inline T ceil_div(T a, U b)
{
@@ -72,16 +69,16 @@ static inline T ceil_div(T a, U b)
}
#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wconsumed"
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wconsumed"
#endif
-template <typename T>
+template<typename T>
T&& move(T& arg)
{
return static_cast<T&&>(arg);
}
#ifdef __clang__
-#pragma clang diagnostic pop
+# pragma clang diagnostic pop
#endif
template<typename T>
@@ -107,26 +104,37 @@ template<typename T, typename U>
void swap(T& a, U& b)
{
U tmp = move((U&)a);
- a = (T&&)move(b);
+ a = (T &&) move(b);
b = move(tmp);
}
template<bool B, class T = void>
-struct EnableIf
-{
+struct EnableIf {
};
template<class T>
-struct EnableIf<true, T>
-{
+struct EnableIf<true, T> {
typedef T Type;
};
-template<class T> struct RemoveConst { typedef T Type; };
-template<class T> struct RemoveConst<const T> { typedef T Type; };
-template<class T> struct RemoveVolatile { typedef T Type; };
-template<class T> struct RemoveVolatile<const T> { typedef T Type; };
-template<class T> struct RemoveCV {
+template<class T>
+struct RemoveConst {
+ typedef T Type;
+};
+template<class T>
+struct RemoveConst<const T> {
+ typedef T Type;
+};
+template<class T>
+struct RemoveVolatile {
+ typedef T Type;
+};
+template<class T>
+struct RemoveVolatile<const T> {
+ typedef T Type;
+};
+template<class T>
+struct RemoveCV {
typedef typename RemoveVolatile<typename RemoveConst<T>::Type>::Type Type;
};
@@ -143,69 +151,145 @@ typedef IntegralConstant<bool, false> FalseType;
typedef IntegralConstant<bool, true> TrueType;
template<class T>
-struct __IsPointerHelper : FalseType { };
+struct __IsPointerHelper : FalseType {
+};
template<class T>
-struct __IsPointerHelper<T*> : TrueType { };
+struct __IsPointerHelper<T*> : TrueType {
+};
template<class T>
-struct IsPointer : __IsPointerHelper<typename RemoveCV<T>::Type> { };
+struct IsPointer : __IsPointerHelper<typename RemoveCV<T>::Type> {
+};
-template<class> struct IsFunction : FalseType { };
+template<class>
+struct IsFunction : FalseType {
+};
-template<class Ret, class... Args> struct IsFunction<Ret(Args...)> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...)> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) const> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) volatile> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) const volatile> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile> : TrueType { };
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...)> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...)> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) const> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) const> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) volatile> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) volatile> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) const volatile> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) const volatile> : TrueType {
+};
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) &> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) &> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) const &> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const &> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile &> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) volatile &> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) const volatile &> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile &> : TrueType { };
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...)&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...)&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) const&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) const&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) volatile&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) volatile&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) const volatile&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) const volatile&> : TrueType {
+};
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) &&> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) &&> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) const &&> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const &&> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) volatile &&> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) volatile &&> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...) const volatile &&> : TrueType { };
-template<class Ret, class... Args> struct IsFunction<Ret(Args...,...) const volatile &&> : TrueType { };
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) &&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) &&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) const&&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) const&&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) volatile&&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) volatile&&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args...) const volatile&&> : TrueType {
+};
+template<class Ret, class... Args>
+struct IsFunction<Ret(Args..., ...) const volatile&&> : TrueType {
+};
-template<class T> struct IsRvalueReference : FalseType { };
-template<class T> struct IsRvalueReference<T&&> : TrueType { };
+template<class T>
+struct IsRvalueReference : FalseType {
+};
+template<class T>
+struct IsRvalueReference<T&&> : TrueType {
+};
-template<class T> struct RemovePointer { typedef T Type; };
-template<class T> struct RemovePointer<T*> { typedef T Type; };
-template<class T> struct RemovePointer<T* const> { typedef T Type; };
-template<class T> struct RemovePointer<T* volatile> { typedef T Type; };
-template<class T> struct RemovePointer<T* const volatile> { typedef T Type; };
+template<class T>
+struct RemovePointer {
+ typedef T Type;
+};
+template<class T>
+struct RemovePointer<T*> {
+ typedef T Type;
+};
+template<class T>
+struct RemovePointer<T* const> {
+ typedef T Type;
+};
+template<class T>
+struct RemovePointer<T* volatile> {
+ typedef T Type;
+};
+template<class T>
+struct RemovePointer<T* const volatile> {
+ typedef T Type;
+};
template<typename T, typename U>
struct IsSame {
- enum { value = 0 };
+ enum {
+ value = 0
+ };
};
template<typename T>
struct IsSame<T, T> {
- enum { value = 1 };
+ enum {
+ value = 1
+ };
};
}
-using AK::min;
+using AK::ceil_div;
+using AK::exchange;
+using AK::forward;
+using AK::IsSame;
using AK::max;
+using AK::min;
using AK::move;
-using AK::forward;
-using AK::exchange;
using AK::swap;
-using AK::ceil_div;
-using AK::IsSame;
diff --git a/AK/String.cpp b/AK/String.cpp
index 8544e4c98a..5ec6f355ee 100644
--- a/AK/String.cpp
+++ b/AK/String.cpp
@@ -38,7 +38,7 @@ String String::empty()
String String::isolated_copy() const
{
if (!m_impl)
- return { };
+ return {};
if (!m_impl->length())
return empty();
char* buffer;
@@ -50,7 +50,7 @@ String String::isolated_copy() const
String String::substring(int start, int length) const
{
if (!length)
- return { };
+ return {};
ASSERT(m_impl);
ASSERT(start + length <= m_impl->length());
// FIXME: This needs some input bounds checking.
@@ -60,7 +60,7 @@ String String::substring(int start, int length) const
StringView String::substring_view(int start, int length) const
{
if (!length)
- return { };
+ return {};
ASSERT(m_impl);
ASSERT(start + length <= m_impl->length());
// FIXME: This needs some input bounds checking.
@@ -70,7 +70,7 @@ StringView String::substring_view(int start, int length) const
Vector<String> String::split(const char separator) const
{
if (is_empty())
- return { };
+ return {};
Vector<String> v;
ssize_t substart = 0;
@@ -94,7 +94,7 @@ Vector<String> String::split(const char separator) const
Vector<StringView> String::split_view(const char separator) const
{
if (is_empty())
- return { };
+ return {};
Vector<StringView> v;
ssize_t substart = 0;
@@ -232,7 +232,7 @@ bool String::match_helper(const String& mask) const
if (!*++mask_ptr)
return true;
mp = mask_ptr;
- cp = string_ptr+1;
+ cp = string_ptr + 1;
} else if ((*mask_ptr == *string_ptr) || (*mask_ptr == '?')) {
mask_ptr++;
string_ptr++;
diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp
index 08776dd3f3..0fe550242e 100644
--- a/AK/StringBuilder.cpp
+++ b/AK/StringBuilder.cpp
@@ -1,7 +1,7 @@
#include "StringBuilder.h"
-#include <LibC/stdarg.h>
#include "printf.cpp"
#include <AK/StdLibExtras.h>
+#include <LibC/stdarg.h>
namespace AK {
@@ -43,9 +43,10 @@ void StringBuilder::append(char ch)
void StringBuilder::appendvf(const char* fmt, va_list ap)
{
- printf_internal([this] (char*&, char ch) {
+ printf_internal([this](char*&, char ch) {
append(ch);
- }, nullptr, fmt, ap);
+ },
+ nullptr, fmt, ap);
}
void StringBuilder::appendf(const char* fmt, ...)
@@ -71,4 +72,3 @@ String StringBuilder::to_string()
}
}
-
diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h
index f6c17dbf85..700540942a 100644
--- a/AK/StringBuilder.h
+++ b/AK/StringBuilder.h
@@ -9,7 +9,7 @@ namespace AK {
class StringBuilder {
public:
explicit StringBuilder(ssize_t initial_capacity = 16);
- ~StringBuilder() { }
+ ~StringBuilder() {}
void append(const String&);
void append(char);
@@ -30,4 +30,3 @@ private:
}
using AK::StringBuilder;
-
diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp
index 5b8e6c742f..2799e237d6 100644
--- a/AK/StringImpl.cpp
+++ b/AK/StringImpl.cpp
@@ -1,7 +1,7 @@
#include "StringImpl.h"
+#include "HashTable.h"
#include "StdLibExtras.h"
#include "kmalloc.h"
-#include "HashTable.h"
//#define DEBUG_STRINGIMPL
@@ -26,7 +26,8 @@ static StringImpl* s_the_empty_stringimpl = nullptr;
StringImpl& StringImpl::the_empty_stringimpl()
{
if (!s_the_empty_stringimpl)
- s_the_empty_stringimpl = new StringImpl(ConstructTheEmptyStringImpl);;
+ s_the_empty_stringimpl = new StringImpl(ConstructTheEmptyStringImpl);
+ ;
return *s_the_empty_stringimpl;
}
@@ -168,4 +169,3 @@ void StringImpl::compute_hash() const
}
}
-
diff --git a/AK/StringImpl.h b/AK/StringImpl.h
index c7ecfd3c24..babca34e10 100644
--- a/AK/StringImpl.h
+++ b/AK/StringImpl.h
@@ -1,12 +1,15 @@
#pragma once
-#include "Retainable.h"
#include "RetainPtr.h"
+#include "Retainable.h"
#include "Types.h"
namespace AK {
-enum ShouldChomp { NoChomp, Chomp };
+enum ShouldChomp {
+ NoChomp,
+ Chomp
+};
class StringImpl : public Retainable<StringImpl> {
public:
@@ -22,7 +25,11 @@ public:
ssize_t length() const { return m_length; }
const char* characters() const { return m_characters; }
- char operator[](ssize_t i) const { ASSERT(i >= 0 && i < m_length); return m_characters[i]; }
+ char operator[](ssize_t i) const
+ {
+ ASSERT(i >= 0 && i < m_length);
+ return m_characters[i];
+ }
unsigned hash() const
{
@@ -32,10 +39,17 @@ public:
}
private:
- enum ConstructTheEmptyStringImplTag { ConstructTheEmptyStringImpl };
- explicit StringImpl(ConstructTheEmptyStringImplTag) : m_characters("") { }
+ enum ConstructTheEmptyStringImplTag {
+ ConstructTheEmptyStringImpl
+ };
+ explicit StringImpl(ConstructTheEmptyStringImplTag)
+ : m_characters("")
+ {
+ }
- enum ConstructWithInlineBufferTag { ConstructWithInlineBuffer };
+ enum ConstructWithInlineBufferTag {
+ ConstructWithInlineBuffer
+ };
StringImpl(ConstructWithInlineBufferTag, ssize_t length);
void compute_hash() const;
@@ -63,6 +77,6 @@ inline dword string_hash(const char* characters, int length)
}
-using AK::StringImpl;
using AK::Chomp;
using AK::string_hash;
+using AK::StringImpl;
diff --git a/AK/StringView.cpp b/AK/StringView.cpp
index 06fe6752e5..77fc057c39 100644
--- a/AK/StringView.cpp
+++ b/AK/StringView.cpp
@@ -1,12 +1,12 @@
-#include <AK/StringView.h>
#include <AK/AKString.h>
+#include <AK/StringView.h>
namespace AK {
Vector<StringView> StringView::split_view(const char separator) const
{
if (is_empty())
- return { };
+ return {};
Vector<StringView> v;
ssize_t substart = 0;
@@ -30,7 +30,7 @@ Vector<StringView> StringView::split_view(const char separator) const
StringView StringView::substring_view(int start, int length) const
{
if (!length)
- return { };
+ return {};
ASSERT(start + length <= m_length);
return { m_characters + start, length };
}
@@ -50,5 +50,4 @@ unsigned StringView::to_uint(bool& ok) const
return value;
}
-
}
diff --git a/AK/StringView.h b/AK/StringView.h
index 51ccd2f67c..ced68488a0 100644
--- a/AK/StringView.h
+++ b/AK/StringView.h
@@ -8,9 +8,17 @@ class String;
class StringView {
public:
- StringView() { }
- StringView(const char* characters, int length) : m_characters(characters), m_length(length) { }
- StringView(const unsigned char* characters, int length) : m_characters((const char*)characters), m_length(length) { }
+ StringView() {}
+ StringView(const char* characters, int length)
+ : m_characters(characters)
+ , m_length(length)
+ {
+ }
+ StringView(const unsigned char* characters, int length)
+ : m_characters((const char*)characters)
+ , m_length(length)
+ {
+ }
StringView(const char* cstring)
: m_characters(cstring)
{
diff --git a/AK/TemporaryChange.h b/AK/TemporaryChange.h
index 274672a490..6248bb865b 100644
--- a/AK/TemporaryChange.h
+++ b/AK/TemporaryChange.h
@@ -5,7 +5,12 @@ namespace AK {
template<typename T>
class TemporaryChange {
public:
- TemporaryChange(T& variable, T value) : m_variable(variable), m_old_value(variable) { m_variable = value; }
+ TemporaryChange(T& variable, T value)
+ : m_variable(variable)
+ , m_old_value(variable)
+ {
+ m_variable = value;
+ }
~TemporaryChange() { m_variable = m_old_value; }
private:
diff --git a/AK/Traits.h b/AK/Traits.h
index 7c88a2e7cb..c147fa3cbd 100644
--- a/AK/Traits.h
+++ b/AK/Traits.h
@@ -1,13 +1,12 @@
#pragma once
-#include "kstdio.h"
#include "HashFunctions.h"
+#include "kstdio.h"
namespace AK {
template<typename T>
-struct Traits
-{
+struct Traits {
};
template<>
@@ -38,4 +37,3 @@ struct Traits<T*> {
};
}
-
diff --git a/AK/Types.h b/AK/Types.h
index fb8501d21d..6764995430 100644
--- a/AK/Types.h
+++ b/AK/Types.h
@@ -30,8 +30,8 @@ typedef signed_dword int32_t;
typedef signed_qword int64_t;
#else
-#include <stdint.h>
-#include <sys/types.h>
+# include <stdint.h>
+# include <sys/types.h>
typedef uint8_t byte;
typedef uint16_t word;
@@ -48,9 +48,11 @@ constexpr unsigned KB = 1024;
constexpr unsigned MB = KB * KB;
constexpr unsigned GB = KB * KB * KB;
-enum class IterationDecision { Continue, Abort };
+enum class IterationDecision {
+ Continue,
+ Abort
+};
namespace std {
typedef decltype(nullptr) nullptr_t;
}
-
diff --git a/AK/Vector.h b/AK/Vector.h
index 2ebe8f92b1..c1b9c5622f 100644
--- a/AK/Vector.h
+++ b/AK/Vector.h
@@ -112,8 +112,16 @@ public:
return m_outline_buffer;
}
- const T& at(int i) const { ASSERT(i >= 0 && i < m_size); return data()[i]; }
- T& at(int i) { ASSERT(i >= 0 && i < m_size); return data()[i]; }
+ const T& at(int i) const
+ {
+ ASSERT(i >= 0 && i < m_size);
+ return data()[i];
+ }
+ T& at(int i)
+ {
+ ASSERT(i >= 0 && i < m_size);
+ return data()[i];
+ }
const T& operator[](int i) const { return at(i); }
T& operator[](int i) { return at(i); }
@@ -314,8 +322,16 @@ public:
bool operator<(const Iterator& other) { return m_index < other.m_index; }
bool operator>(const Iterator& other) { return m_index > other.m_index; }
bool operator>=(const Iterator& other) { return m_index >= other.m_index; }
- Iterator& operator++() { ++m_index; return *this; }
- Iterator& operator--() { --m_index; return *this; }
+ Iterator& operator++()
+ {
+ ++m_index;
+ return *this;
+ }
+ Iterator& operator--()
+ {
+ --m_index;
+ return *this;
+ }
Iterator operator-(int value) { return { m_vector, m_index - value }; }
Iterator operator+(int value) { return { m_vector, m_index + value }; }
Iterator& operator=(const Iterator& other)
@@ -325,9 +341,14 @@ public:
}
T& operator*() { return m_vector[m_index]; }
int operator-(const Iterator& other) { return m_index - other.m_index; }
+
private:
friend class Vector;
- Iterator(Vector& vector, int index) : m_vector(vector), m_index(index) { }
+ Iterator(Vector& vector, int index)
+ : m_vector(vector)
+ , m_index(index)
+ {
+ }
Vector& m_vector;
int m_index { 0 };
};
@@ -342,8 +363,16 @@ public:
bool operator<(const ConstIterator& other) { return m_index < other.m_index; }
bool operator>(const ConstIterator& other) { return m_index > other.m_index; }
bool operator>=(const ConstIterator& other) { return m_index >= other.m_index; }
- ConstIterator& operator++() { ++m_index; return *this; }
- ConstIterator& operator--() { --m_index; return *this; }
+ ConstIterator& operator++()
+ {
+ ++m_index;
+ return *this;
+ }
+ ConstIterator& operator--()
+ {
+ --m_index;
+ return *this;
+ }
ConstIterator operator-(int value) { return { m_vector, m_index - value }; }
ConstIterator operator+(int value) { return { m_vector, m_index + value }; }
ConstIterator& operator=(const ConstIterator& other)
@@ -353,9 +382,14 @@ public:
}
const T& operator*() const { return m_vector[m_index]; }
int operator-(const ConstIterator& other) { return m_index - other.m_index; }
+
private:
friend class Vector;
- ConstIterator(const Vector& vector, const int index) : m_vector(vector), m_index(index) { }
+ ConstIterator(const Vector& vector, const int index)
+ : m_vector(vector)
+ , m_index(index)
+ {
+ }
const Vector& m_vector;
int m_index { 0 };
};
@@ -377,8 +411,16 @@ private:
T* slot(int i) { return &data()[i]; }
const T* slot(int i) const { return &data()[i]; }
- T* inline_buffer() { static_assert(inline_capacity > 0); return reinterpret_cast<T*>(m_inline_buffer_storage); }
- const T* inline_buffer() const { static_assert(inline_capacity > 0); return reinterpret_cast<const T*>(m_inline_buffer_storage); }
+ T* inline_buffer()
+ {
+ static_assert(inline_capacity > 0);
+ return reinterpret_cast<T*>(m_inline_buffer_storage);
+ }
+ const T* inline_buffer() const
+ {
+ static_assert(inline_capacity > 0);
+ return reinterpret_cast<const T*>(m_inline_buffer_storage);
+ }
int m_size { 0 };
int m_capacity { 0 };
diff --git a/AK/WeakPtr.h b/AK/WeakPtr.h
index 89dbcd93f4..30d118e178 100644
--- a/AK/WeakPtr.h
+++ b/AK/WeakPtr.h
@@ -4,14 +4,16 @@
namespace AK {
-template<typename T> class OwnPtr;
+template<typename T>
+class OwnPtr;
template<typename T>
class WeakPtr {
friend class Weakable<T>;
+
public:
- WeakPtr() { }
- WeakPtr(std::nullptr_t) { }
+ WeakPtr() {}
+ WeakPtr(std::nullptr_t) {}
template<typename U>
WeakPtr(WeakPtr<U>&& other)
@@ -48,7 +50,10 @@ public:
bool operator==(const OwnPtr<T>& other) const { return ptr() == other.ptr(); }
private:
- WeakPtr(RetainPtr<WeakLink<T>>&& link) : m_link(move(link)) { }
+ WeakPtr(RetainPtr<WeakLink<T>>&& link)
+ : m_link(move(link))
+ {
+ }
RetainPtr<WeakLink<T>> m_link;
};
@@ -64,4 +69,3 @@ inline WeakPtr<T> Weakable<T>::make_weak_ptr()
}
using AK::WeakPtr;
-
diff --git a/AK/Weakable.h b/AK/Weakable.h
index c9590c2be1..d5b55050d3 100644
--- a/AK/Weakable.h
+++ b/AK/Weakable.h
@@ -1,23 +1,29 @@
#pragma once
#include "Assertions.h"
-#include "Retainable.h"
#include "RetainPtr.h"
+#include "Retainable.h"
namespace AK {
-template<typename T> class Weakable;
-template<typename T> class WeakPtr;
+template<typename T>
+class Weakable;
+template<typename T>
+class WeakPtr;
template<typename T>
class WeakLink : public Retainable<WeakLink<T>> {
friend class Weakable<T>;
+
public:
T* ptr() { return static_cast<T*>(m_ptr); }
const T* ptr() const { return static_cast<const T*>(m_ptr); }
private:
- explicit WeakLink(T& weakable) : m_ptr(&weakable) { }
+ explicit WeakLink(T& weakable)
+ : m_ptr(&weakable)
+ {
+ }
T* m_ptr;
};
@@ -25,11 +31,12 @@ template<typename T>
class Weakable {
private:
class Link;
+
public:
WeakPtr<T> make_weak_ptr();
protected:
- Weakable() { }
+ Weakable() {}
~Weakable()
{
diff --git a/AK/kmalloc.h b/AK/kmalloc.h
index c31352ec01..c1068d7f67 100644
--- a/AK/kmalloc.h
+++ b/AK/kmalloc.h
@@ -1,25 +1,26 @@
#pragma once
#ifdef KERNEL
-#define AK_MAKE_ETERNAL \
-public: \
- void* operator new(size_t size) { return kmalloc_eternal(size); } \
-private:
+# define AK_MAKE_ETERNAL \
+ public: \
+ void* operator new(size_t size) { return kmalloc_eternal(size); } \
+ \
+ private:
#else
-#define AK_MAKE_ETERNAL
+# define AK_MAKE_ETERNAL
#endif
#ifdef KERNEL
-#include <Kernel/kmalloc.h>
+# include <Kernel/kmalloc.h>
#else
-#include <stdlib.h>
+# include <stdlib.h>
-#define kcalloc calloc
-#define kmalloc malloc
-#define kfree free
-#define krealloc realloc
+# define kcalloc calloc
+# define kmalloc malloc
+# define kfree free
+# define krealloc realloc
-#ifdef __serenity__
+# ifdef __serenity__
inline void* operator new(size_t size)
{
return kmalloc(size);
@@ -44,6 +45,6 @@ inline void* operator new(size_t, void* ptr)
{
return ptr;
}
-#endif
+# endif
#endif
diff --git a/AK/printf.cpp b/AK/printf.cpp
index 68d29e5dc6..0b5ee149ad 100644
--- a/AK/printf.cpp
+++ b/AK/printf.cpp
@@ -169,7 +169,6 @@ template<typename PutChFunc>
return fieldWidth;
}
-
template<typename PutChFunc>
[[gnu::always_inline]] inline int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth)
{
@@ -183,7 +182,7 @@ template<typename PutChFunc>
template<typename PutChFunc>
[[gnu::always_inline]] inline int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap)
{
- const char *p;
+ const char* p;
int ret = 0;
char* bufptr = buffer;
@@ -195,7 +194,7 @@ template<typename PutChFunc>
unsigned long_qualifiers = 0;
bool alternate_form = 0;
if (*p == '%' && *(p + 1)) {
-one_more:
+ one_more:
++p;
if (*p == ' ') {
leftPad = true;
@@ -223,87 +222,81 @@ one_more:
if (*(p + 1))
goto one_more;
}
- switch( *p )
- {
- case 's':
- {
- const char* sp = va_arg(ap, const char*);
- ret += print_string(putch, bufptr, sp ? sp : "(null)", leftPad, fieldWidth);
- }
- break;
-
- case 'd':
- ret += print_signed_number(putch, bufptr, va_arg(ap, int), leftPad, zeroPad, fieldWidth);
- break;
-
- case 'u':
- ret += print_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth);
- break;
-
- case 'Q':
- ret += print_qword(putch, bufptr, va_arg(ap, qword), leftPad, zeroPad, fieldWidth);
- break;
-
- case 'q':
- ret += print_hex(putch, bufptr, va_arg(ap, qword), 16);
- break;
+ switch (*p) {
+ case 's': {
+ const char* sp = va_arg(ap, const char*);
+ ret += print_string(putch, bufptr, sp ? sp : "(null)", leftPad, fieldWidth);
+ } break;
+
+ case 'd':
+ ret += print_signed_number(putch, bufptr, va_arg(ap, int), leftPad, zeroPad, fieldWidth);
+ break;
+
+ case 'u':
+ ret += print_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth);
+ break;
+
+ case 'Q':
+ ret += print_qword(putch, bufptr, va_arg(ap, qword), leftPad, zeroPad, fieldWidth);
+ break;
+
+ case 'q':
+ ret += print_hex(putch, bufptr, va_arg(ap, qword), 16);
+ break;
#ifndef KERNEL
- case 'f':
- // FIXME: Print as float!
- ret += print_number(putch, bufptr, (int)va_arg(ap, double), leftPad, zeroPad, fieldWidth);
- break;
+ case 'f':
+ // FIXME: Print as float!
+ ret += print_number(putch, bufptr, (int)va_arg(ap, double), leftPad, zeroPad, fieldWidth);
+ break;
#endif
- case 'o':
- if (alternate_form) {
- putch(bufptr, '0');
- ++ret;
- }
- ret += print_octal_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth);
- break;
-
- case 'x':
- if (alternate_form) {
- putch(bufptr, '0');
- putch(bufptr, 'x');
- ret += 2;
- }
- ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
- break;
-
- case 'w':
- ret += print_hex(putch, bufptr, va_arg(ap, int), 4);
- break;
-
- case 'b':
- ret += print_hex(putch, bufptr, va_arg(ap, int), 2);
- break;
-
- case 'c':
- putch(bufptr, (char)va_arg(ap, int));
- ++ret;
- break;
-
- case '%':
- putch(bufptr, '%');
+ case 'o':
+ if (alternate_form) {
+ putch(bufptr, '0');
++ret;
- break;
+ }
+ ret += print_octal_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth);
+ break;
- case 'p':
+ case 'x':
+ if (alternate_form) {
putch(bufptr, '0');
putch(bufptr, 'x');
ret += 2;
- ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
- break;
+ }
+ ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
+ break;
+
+ case 'w':
+ ret += print_hex(putch, bufptr, va_arg(ap, int), 4);
+ break;
+
+ case 'b':
+ ret += print_hex(putch, bufptr, va_arg(ap, int), 2);
+ break;
+
+ case 'c':
+ putch(bufptr, (char)va_arg(ap, int));
+ ++ret;
+ break;
+
+ case '%':
+ putch(bufptr, '%');
+ ++ret;
+ break;
+
+ case 'p':
+ putch(bufptr, '0');
+ putch(bufptr, 'x');
+ ret += 2;
+ ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
+ break;
}
- }
- else {
+ } else {
putch(bufptr, *p);
++ret;
}
}
return ret;
}
-
-