1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:27:35 +00:00

Yet another pass of style fixes.

This commit is contained in:
Andreas Kling 2018-12-21 02:10:45 +01:00
parent 89040cdc99
commit ec1c487dcd
43 changed files with 183 additions and 185 deletions

View file

@ -46,25 +46,25 @@ public:
unsigned toUInt(bool& ok) const;
String toLowercase() const
String to_lowercase() const
{
if (!m_impl)
return String();
return m_impl->toLowercase();
return m_impl->to_lowercase();
}
String toUppercase() const
String to_uppercase() const
{
if (!m_impl)
return String();
return m_impl->toUppercase();
return m_impl->to_uppercase();
}
Vector<String> split(char separator) const;
String substring(size_t start, size_t length) const;
bool isNull() const { return !m_impl; }
bool isEmpty() const { return length() == 0; }
bool is_null() const { return !m_impl; }
bool is_empty() const { return length() == 0; }
unsigned length() const { return m_impl ? m_impl->length() : 0; }
const char* characters() const { return m_impl ? m_impl->characters() : nullptr; }
char operator[](unsigned i) const { ASSERT(m_impl); return (*m_impl)[i]; }
@ -72,7 +72,7 @@ public:
bool operator==(const String&) const;
bool operator!=(const String& other) const { return !(*this == other); }
String isolatedCopy() const;
String isolated_copy() const;
static String empty();
@ -93,7 +93,7 @@ public:
return *this;
}
ByteBuffer toByteBuffer() const;
ByteBuffer to_byte_buffer() const;
private:
RetainPtr<StringImpl> m_impl;

View file

@ -11,7 +11,7 @@ namespace AK {
template<typename T>
class Buffer : public Retainable<Buffer<T>> {
public:
static RetainPtr<Buffer> createUninitialized(size_t count);
static RetainPtr<Buffer> create_uninitialized(size_t count);
static RetainPtr<Buffer> copy(const T*, size_t count);
static RetainPtr<Buffer> wrap(T*, size_t count);
static RetainPtr<Buffer> adopt(T*, size_t count);
@ -29,16 +29,16 @@ public:
T& operator[](size_t i) { ASSERT(i < m_size); return m_elements[i]; }
const T& operator[](size_t i) const { ASSERT(i < m_size); return m_elements[i]; }
bool isEmpty() const { return !m_size; }
bool is_empty() const { return !m_size; }
size_t size() const { return m_size; }
T* pointer() { return m_elements; }
const T* pointer() const { return m_elements; }
T* offsetPointer(size_t offset) { return m_elements + offset; }
const T* offsetPointer(size_t offset) const { return m_elements + offset; }
T* offset_pointer(size_t offset) { return m_elements + offset; }
const T* offset_pointer(size_t offset) const { return m_elements + offset; }
const void* endPointer() const { return m_elements + m_size; }
const void* end_pointer() const { return m_elements + m_size; }
// NOTE: trim() does not reallocate.
void trim(size_t size)
@ -91,7 +91,7 @@ inline Buffer<T>::Buffer(T* elements, size_t size, ConstructionMode mode)
}
template<typename T>
inline RetainPtr<Buffer<T>> Buffer<T>::createUninitialized(size_t size)
inline RetainPtr<Buffer<T>> Buffer<T>::create_uninitialized(size_t size)
{
return ::adopt(*new Buffer<T>(size));
}

View file

@ -30,8 +30,7 @@ public:
return *this;
}
static ByteBuffer createEmpty() { return ByteBuffer(Buffer<byte>::createUninitialized(0)); }
static ByteBuffer createUninitialized(size_t size) { return ByteBuffer(Buffer<byte>::createUninitialized(size)); }
static ByteBuffer create_uninitialized(size_t size) { return ByteBuffer(Buffer<byte>::create_uninitialized(size)); }
static ByteBuffer copy(const byte* data, size_t size) { return ByteBuffer(Buffer<byte>::copy(data, size)); }
static ByteBuffer wrap(byte* data, size_t size) { return ByteBuffer(Buffer<byte>::wrap(data, size)); }
static ByteBuffer adopt(byte* data, size_t size) { return ByteBuffer(Buffer<byte>::adopt(data, size)); }
@ -39,22 +38,22 @@ public:
~ByteBuffer() { clear(); }
void clear() { m_impl = nullptr; }
operator bool() const { return !isNull(); }
bool operator!() const { return isNull(); }
bool isNull() const { return m_impl == nullptr; }
operator bool() const { return !is_null(); }
bool operator!() const { return is_null(); }
bool is_null() const { return m_impl == nullptr; }
byte& operator[](size_t i) { ASSERT(m_impl); return (*m_impl)[i]; }
byte operator[](size_t i) const { ASSERT(m_impl); return (*m_impl)[i]; }
bool isEmpty() const { return !m_impl || m_impl->isEmpty(); }
bool is_empty() const { return !m_impl || m_impl->is_empty(); }
size_t size() const { return m_impl ? m_impl->size() : 0; }
byte* pointer() { return m_impl ? m_impl->pointer() : nullptr; }
const byte* pointer() const { return m_impl ? m_impl->pointer() : nullptr; }
byte* offsetPointer(size_t offset) { return m_impl ? m_impl->offsetPointer(offset) : nullptr; }
const byte* offsetPointer(size_t offset) const { return m_impl ? m_impl->offsetPointer(offset) : nullptr; }
byte* offset_pointer(size_t offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
const byte* offset_pointer(size_t offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
const void* endPointer() const { return m_impl ? m_impl->endPointer() : nullptr; }
const void* end_pointer() const { return m_impl ? m_impl->end_pointer() : nullptr; }
// NOTE: trim() does not reallocate.
void trim(size_t size)
@ -65,13 +64,13 @@ public:
ByteBuffer slice(size_t offset, size_t size) const
{
if (isNull())
if (is_null())
return { };
if (offset >= this->size())
return { };
if (offset + size >= this->size())
size = this->size() - offset;
return copy(offsetPointer(offset), size);
return copy(offset_pointer(offset), size);
}
private:

View file

@ -19,7 +19,7 @@ public:
DoublyLinkedList() { }
~DoublyLinkedList() { clear(); }
bool isEmpty() const { return !head(); }
bool is_empty() const { return !head(); }
void clear()
{

View file

@ -22,14 +22,14 @@ bool FileSystemPath::canonicalize(bool resolve_symbolic_links)
if (part == ".")
continue;
if (part == "..") {
if (!canonical_parts.isEmpty())
if (!canonical_parts.is_empty())
canonical_parts.takeLast();
continue;
}
if (!part.isEmpty())
if (!part.is_empty())
canonical_parts.append(part);
}
if (canonical_parts.isEmpty()) {
if (canonical_parts.is_empty()) {
m_string = m_basename = "/";
return true;
}

View file

@ -46,7 +46,7 @@ public:
return *this;
}
bool isEmpty() const { return m_table.isEmpty(); }
bool is_empty() const { return m_table.is_empty(); }
unsigned size() const { return m_table.size(); }
unsigned capacity() const { return m_table.capacity(); }
void clear() { m_table.clear(); }

View file

@ -44,7 +44,7 @@ public:
}
~HashTable() { clear(); }
bool isEmpty() const { return !m_size; }
bool is_empty() const { return !m_size; }
unsigned size() const { return m_size; }
unsigned capacity() const { return m_capacity; }
@ -112,7 +112,7 @@ public:
, m_isEnd(isEnd)
, m_bucketIterator(bucketIterator)
{
if (!isEnd && !m_table.isEmpty() && !(m_bucketIterator != DoublyLinkedList<T>::Iterator::universalEnd())) {
if (!isEnd && !m_table.is_empty() && !(m_bucketIterator != DoublyLinkedList<T>::Iterator::universalEnd())) {
#ifdef HASHTABLE_DEBUG
kprintf("bucket iterator init!\n");
#endif
@ -128,7 +128,7 @@ public:
typename DoublyLinkedList<T>::Iterator m_bucketIterator;
};
Iterator begin() { return Iterator(*this, isEmpty()); }
Iterator begin() { return Iterator(*this, is_empty()); }
Iterator end() { return Iterator(*this, true); }
class ConstIterator {
@ -189,7 +189,7 @@ public:
, m_isEnd(isEnd)
, m_bucketIterator(bucketIterator)
{
if (!isEnd && !m_table.isEmpty() && !(m_bucketIterator != DoublyLinkedList<T>::ConstIterator::universalEnd())) {
if (!isEnd && !m_table.is_empty() && !(m_bucketIterator != DoublyLinkedList<T>::ConstIterator::universalEnd())) {
#ifdef HASHTABLE_DEBUG
kprintf("const bucket iterator init!\n");
#endif
@ -206,7 +206,7 @@ public:
typename DoublyLinkedList<T>::ConstIterator m_bucketIterator;
};
ConstIterator begin() const { return ConstIterator(*this, isEmpty()); }
ConstIterator begin() const { return ConstIterator(*this, is_empty()); }
ConstIterator end() const { return ConstIterator(*this, true); }
Iterator find(const T&);
@ -323,7 +323,7 @@ void HashTable<T, TraitsForT>::insert(const T& value)
template<typename T, typename TraitsForT>
bool HashTable<T, TraitsForT>::contains(const T& value) const
{
if (isEmpty())
if (is_empty())
return false;
auto& bucket = lookup(value);
for (auto& e : bucket.chain) {
@ -336,7 +336,7 @@ bool HashTable<T, TraitsForT>::contains(const T& value) const
template<typename T, typename TraitsForT>
auto HashTable<T, TraitsForT>::find(const T& value) -> Iterator
{
if (isEmpty())
if (is_empty())
return end();
unsigned bucketIndex;
auto& bucket = lookup(value, &bucketIndex);
@ -349,7 +349,7 @@ auto HashTable<T, TraitsForT>::find(const T& value) -> Iterator
template<typename T, typename TraitsForT>
auto HashTable<T, TraitsForT>::find(const T& value) const -> ConstIterator
{
if (isEmpty())
if (is_empty())
return end();
unsigned bucketIndex;
auto& bucket = lookup(value, &bucketIndex);
@ -362,7 +362,7 @@ auto HashTable<T, TraitsForT>::find(const T& value) const -> ConstIterator
template<typename T, typename TraitsForT>
void HashTable<T, TraitsForT>::remove(Iterator it)
{
ASSERT(!isEmpty());
ASSERT(!is_empty());
m_buckets[it.m_bucketIndex].chain.remove(it.m_bucketIterator);
--m_size;
}

View file

@ -9,8 +9,8 @@ template<typename T> class InlineLinkedListNode {
public:
InlineLinkedListNode();
void setPrev(T*);
void setNext(T*);
void set_prev(T*);
void set_next(T*);
T* prev() const;
T* next() const;
@ -18,16 +18,16 @@ public:
template<typename T> inline InlineLinkedListNode<T>::InlineLinkedListNode()
{
setPrev(0);
setNext(0);
set_prev(0);
set_next(0);
}
template<typename T> inline void InlineLinkedListNode<T>::setPrev(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>::setNext(T* next)
template<typename T> inline void InlineLinkedListNode<T>::set_next(T* next)
{
static_cast<T*>(this)->m_next = next;
}
@ -46,12 +46,12 @@ template<typename T> class InlineLinkedList {
public:
InlineLinkedList() { }
bool isEmpty() const { return !m_head; }
size_t sizeSlow() const;
bool is_empty() const { return !m_head; }
size_t size_slow() const;
void clear();
T* head() const { return m_head; }
T* removeHead();
T* remove_head();
T* tail() const { return m_tail; }
@ -60,7 +60,7 @@ public:
void remove(T*);
void append(InlineLinkedList<T>&);
bool containsSlow(T* value) const
bool contains_slow(T* value) const
{
for (T* node = m_head; node; node = node->next()) {
if (node == value)
@ -74,7 +74,7 @@ private:
T* m_tail { nullptr };
};
template<typename T> inline size_t InlineLinkedList<T>::sizeSlow() 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())
@ -94,15 +94,15 @@ template<typename T> inline void InlineLinkedList<T>::prepend(T* node)
ASSERT(!m_tail);
m_head = node;
m_tail = node;
node->setPrev(0);
node->setNext(0);
node->set_prev(0);
node->set_next(0);
return;
}
ASSERT(m_tail);
m_head->setPrev(node);
node->setNext(m_head);
node->setPrev(0);
m_head->set_prev(node);
node->set_next(m_head);
node->set_prev(0);
m_head = node;
}
@ -112,15 +112,15 @@ template<typename T> inline void InlineLinkedList<T>::append(T* node)
ASSERT(!m_head);
m_head = node;
m_tail = node;
node->setPrev(0);
node->setNext(0);
node->set_prev(0);
node->set_next(0);
return;
}
ASSERT(m_head);
m_tail->setNext(node);
node->setPrev(m_tail);
node->setNext(0);
m_tail->set_next(node);
node->set_prev(m_tail);
node->set_next(0);
m_tail = node;
}
@ -128,7 +128,7 @@ template<typename T> inline void InlineLinkedList<T>::remove(T* node)
{
if (node->prev()) {
ASSERT(node != m_head);
node->prev()->setNext(node->next());
node->prev()->set_next(node->next());
} else {
ASSERT(node == m_head);
m_head = node->next();
@ -136,14 +136,14 @@ template<typename T> inline void InlineLinkedList<T>::remove(T* node)
if (node->next()) {
ASSERT(node != m_tail);
node->next()->setPrev(node->prev());
node->next()->set_prev(node->prev());
} else {
ASSERT(node == m_tail);
m_tail = node->prev();
}
}
template<typename T> inline T* InlineLinkedList<T>::removeHead()
template<typename T> inline T* InlineLinkedList<T>::remove_head()
{
T* node = head();
if (node)
@ -165,19 +165,18 @@ template<typename T> inline void InlineLinkedList<T>::append(InlineLinkedList<T>
ASSERT(tail());
ASSERT(other.head());
T* otherHead = other.head();
T* otherTail = other.tail();
T* other_head = other.head();
T* other_tail = other.tail();
other.clear();
ASSERT(!m_tail->next());
m_tail->setNext(otherHead);
ASSERT(!otherHead->prev());
otherHead->setPrev(m_tail);
m_tail = otherTail;
m_tail->set_next(other_head);
ASSERT(!other_head->prev());
other_head->set_prev(m_tail);
m_tail = other_tail;
}
}
using AK::InlineLinkedList;
using AK::InlineLinkedListNode;

View file

@ -17,7 +17,7 @@ public:
SinglyLinkedList() { }
~SinglyLinkedList() { clear(); }
bool isEmpty() const { return !head(); }
bool is_empty() const { return !head(); }
void clear()
{

View file

@ -19,17 +19,17 @@ bool String::operator==(const String& other) const
String String::empty()
{
return StringImpl::theEmptyStringImpl();
return StringImpl::the_empty_stringimpl();
}
String String::isolatedCopy() const
String String::isolated_copy() const
{
if (!m_impl)
return { };
if (!m_impl->length())
return empty();
char* buffer;
auto impl = StringImpl::createUninitialized(length(), buffer);
auto impl = StringImpl::create_uninitialized(length(), buffer);
memcpy(buffer, m_impl->characters(), m_impl->length());
return String(move(*impl));
}
@ -40,7 +40,7 @@ String String::substring(size_t start, size_t length) const
ASSERT(start + length <= m_impl->length());
// FIXME: This needs some input bounds checking.
char* buffer;
auto newImpl = StringImpl::createUninitialized(length, buffer);
auto newImpl = StringImpl::create_uninitialized(length, buffer);
memcpy(buffer, characters() + start, length);
buffer[length] = '\0';
return newImpl;
@ -48,7 +48,7 @@ String String::substring(size_t start, size_t length) const
Vector<String> String::split(const char separator) const
{
if (isEmpty())
if (is_empty())
return { };
Vector<String> v;
@ -70,7 +70,7 @@ Vector<String> String::split(const char separator) const
return v;
}
ByteBuffer String::toByteBuffer() const
ByteBuffer String::to_byte_buffer() const
{
if (!m_impl)
return nullptr;

View file

@ -20,7 +20,7 @@ void StringBuilder::append(char ch)
String StringBuilder::build()
{
auto strings = move(m_strings);
if (strings.isEmpty())
if (strings.is_empty())
return String::empty();
size_t sizeNeeded = 0;
@ -28,7 +28,7 @@ String StringBuilder::build()
sizeNeeded += string.length();
char* buffer;
auto impl = StringImpl::createUninitialized(sizeNeeded, buffer);
auto impl = StringImpl::create_uninitialized(sizeNeeded, buffer);
if (!impl)
return String();

View file

@ -4,18 +4,18 @@
namespace AK {
static StringImpl* s_theEmptyStringImpl = nullptr;
static StringImpl* s_the_empty_stringimpl = nullptr;
void StringImpl::initializeGlobals()
void StringImpl::initialize_globals()
{
s_theEmptyStringImpl = nullptr;
s_the_empty_stringimpl = nullptr;
}
StringImpl& StringImpl::theEmptyStringImpl()
StringImpl& StringImpl::the_empty_stringimpl()
{
if (!s_theEmptyStringImpl)
s_theEmptyStringImpl = new StringImpl(ConstructTheEmptyStringImpl);;
return *s_theEmptyStringImpl;
if (!s_the_empty_stringimpl)
s_the_empty_stringimpl = new StringImpl(ConstructTheEmptyStringImpl);;
return *s_the_empty_stringimpl;
}
StringImpl::~StringImpl()
@ -27,7 +27,7 @@ static inline size_t allocationSizeForStringImpl(size_t length)
return sizeof(StringImpl) + (sizeof(char) * length) + sizeof(char);
}
RetainPtr<StringImpl> StringImpl::createUninitialized(size_t length, char*& buffer)
RetainPtr<StringImpl> StringImpl::create_uninitialized(size_t length, char*& buffer)
{
ASSERT(length);
void* slot = kmalloc(allocationSizeForStringImpl(length));
@ -46,10 +46,10 @@ RetainPtr<StringImpl> StringImpl::create(const char* cstring, size_t length, Sho
return nullptr;
if (!*cstring)
return theEmptyStringImpl();
return the_empty_stringimpl();
char* buffer;
auto newStringImpl = createUninitialized(length, buffer);
auto newStringImpl = create_uninitialized(length, buffer);
if (!newStringImpl)
return nullptr;
memcpy(buffer, cstring, length * sizeof(char));
@ -94,7 +94,7 @@ static inline char toASCIIUppercase(char c)
return c;
}
RetainPtr<StringImpl> StringImpl::toLowercase() const
RetainPtr<StringImpl> StringImpl::to_lowercase() const
{
if (!m_length)
return const_cast<StringImpl*>(this);
@ -107,7 +107,7 @@ RetainPtr<StringImpl> StringImpl::toLowercase() const
slowPath:
char* buffer;
auto lowercased = createUninitialized(m_length, buffer);
auto lowercased = create_uninitialized(m_length, buffer);
if (!lowercased)
return nullptr;
for (size_t i = 0; i < m_length; ++i)
@ -116,7 +116,7 @@ slowPath:
return lowercased;
}
RetainPtr<StringImpl> StringImpl::toUppercase() const
RetainPtr<StringImpl> StringImpl::to_uppercase() const
{
if (!m_length)
return const_cast<StringImpl*>(this);
@ -129,7 +129,7 @@ RetainPtr<StringImpl> StringImpl::toUppercase() const
slowPath:
char* buffer;
auto uppercased = createUninitialized(m_length, buffer);
auto uppercased = create_uninitialized(m_length, buffer);
if (!uppercased)
return nullptr;
for (size_t i = 0; i < m_length; ++i)
@ -138,7 +138,7 @@ slowPath:
return uppercased;
}
void StringImpl::computeHash() const
void StringImpl::compute_hash() const
{
if (!length()) {
m_hash = 0;

View file

@ -10,14 +10,14 @@ enum ShouldChomp { NoChomp, Chomp };
class StringImpl : public Retainable<StringImpl> {
public:
static RetainPtr<StringImpl> createUninitialized(size_t length, char*& buffer);
static RetainPtr<StringImpl> create_uninitialized(size_t length, char*& buffer);
static RetainPtr<StringImpl> create(const char* cstring, ShouldChomp = NoChomp);
static RetainPtr<StringImpl> create(const char* cstring, size_t length, ShouldChomp = NoChomp);
RetainPtr<StringImpl> toLowercase() const;
RetainPtr<StringImpl> toUppercase() const;
RetainPtr<StringImpl> to_lowercase() const;
RetainPtr<StringImpl> to_uppercase() const;
static StringImpl& theEmptyStringImpl();
static void initializeGlobals();
static StringImpl& the_empty_stringimpl();
static void initialize_globals();
~StringImpl();
@ -28,7 +28,7 @@ public:
unsigned hash() const
{
if (!m_hasHash)
computeHash();
compute_hash();
return m_hash;
}
@ -37,15 +37,15 @@ private:
explicit StringImpl(ConstructTheEmptyStringImplTag) : m_characters("") { }
enum ConstructWithInlineBufferTag { ConstructWithInlineBuffer };
explicit StringImpl(ConstructWithInlineBufferTag, size_t length) : m_length(length), m_characters(m_inlineBuffer) { }
explicit StringImpl(ConstructWithInlineBufferTag, size_t length) : m_length(length), m_characters(m_inline_buffer) { }
void computeHash() const;
void compute_hash() const;
size_t m_length { 0 };
mutable bool m_hasHash { false };
const char* m_characters { nullptr };
mutable unsigned m_hash { 0 };
char m_inlineBuffer[0];
char m_inline_buffer[0];
};
}

View file

@ -109,7 +109,7 @@ public:
return false;
}
bool isEmpty() const { return size() == 0; }
bool is_empty() const { return size() == 0; }
size_t size() const { return m_impl ? m_impl->size() : 0; }
size_t capacity() const { return m_impl ? m_impl->capacity() : 0; }
@ -130,7 +130,7 @@ public:
T takeLast()
{
ASSERT(!isEmpty());
ASSERT(!is_empty());
T value = move(last());
last().~T();
--m_impl->m_size;

View file

@ -29,7 +29,7 @@ public:
T& operator*() { return *ptr(); }
const T& operator*() const { return *ptr(); }
bool isNull() const { return !m_link || !m_link->ptr(); }
bool is_null() const { return !m_link || !m_link->ptr(); }
void clear() { m_link = nullptr; }
WeakLink<T>* leakLink() { return m_link.leakRef(); }

View file

@ -20,7 +20,7 @@ void log_unlocked() { }
int main(int c, char** v)
{
StringImpl::initializeGlobals();
StringImpl::initialize_globals();
{
SpinLock lock;
@ -32,7 +32,7 @@ int main(int c, char** v)
if (c == 2)
testpath = v[1];
FileSystemPath p(testpath);
if (p.string().isNull())
if (p.string().is_null())
printf("canonicalized path is null\n");
else
printf("%s\n", p.string().characters());
@ -108,14 +108,14 @@ int main(int c, char** v)
String empty = "";
char* buffer;
auto test = StringImpl::createUninitialized(3, buffer);
auto test = StringImpl::create_uninitialized(3, buffer);
auto hello = String("hello");
auto Hello = String("Hello");
printf("hello: '%s'\n", hello.characters());
printf("Hello: '%s'\n", Hello.characters());
printf("'Hello'.lower(): '%s'\n", Hello.toLowercase().characters());
printf("'hello'.upper(): '%s'\n", Hello.toUppercase().characters());
printf("'Hello'.lower(): '%s'\n", Hello.to_lowercase().characters());
printf("'hello'.upper(): '%s'\n", Hello.to_uppercase().characters());
Vector<String> strings;
strings.append("a");
@ -188,7 +188,7 @@ int main(int c, char** v)
list.append(3);
list.append(6);
list.append(9);
ASSERT(!list.isEmpty());
ASSERT(!list.is_empty());
ASSERT(list.first() == 3);
ASSERT(list.last() == 9);
@ -213,7 +213,7 @@ int main(int c, char** v)
printf("not found\n");
}
auto charbuf = Buffer<char>::createUninitialized(1024);
auto charbuf = Buffer<char>::create_uninitialized(1024);
printf("charbuf.size() = %zu\n", charbuf->size());
{