diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index 51227e0b71c..3147d90534a 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -2,9 +2,7 @@ #include "Buffer.h" #include "Types.h" -#include -#include -#include +#include "StdLib.h" namespace AK { @@ -17,13 +15,13 @@ public: { } ByteBuffer(ByteBuffer&& other) - : m_impl(std::move(other.m_impl)) + : m_impl(move(other.m_impl)) { } ByteBuffer& operator=(ByteBuffer&& other) { if (this != &other) - m_impl = std::move(other.m_impl); + m_impl = move(other.m_impl); return *this; } @@ -73,7 +71,7 @@ public: private: explicit ByteBuffer(RetainPtr>&& impl) - : m_impl(std::move(impl)) + : m_impl(move(impl)) { } diff --git a/AK/RetainPtr.h b/AK/RetainPtr.h index f4af4d860ba..5bc6ba62873 100644 --- a/AK/RetainPtr.h +++ b/AK/RetainPtr.h @@ -1,7 +1,8 @@ #pragma once -#include -#include +namespace std { +typedef decltype(nullptr) nullptr_t; +} namespace AK { diff --git a/AK/StdLib.h b/AK/StdLib.h index c23609451e1..5c70559087a 100644 --- a/AK/StdLib.h +++ b/AK/StdLib.h @@ -24,6 +24,11 @@ static inline T ceilDiv(T a, T b) return result; } +template +T&& move(T& arg) +{ + return static_cast(arg); +} } diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 0d7016973ae..6276c20a0e8 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -17,12 +17,12 @@ StringImpl::~StringImpl() { } -static inline size_t allocationSizeForStringImpl(unsigned length) +static inline size_t allocationSizeForStringImpl(size_t length) { return sizeof(StringImpl) + (sizeof(char) * length) + sizeof(char); } -RetainPtr StringImpl::createUninitialized(unsigned length, char*& buffer) +RetainPtr StringImpl::createUninitialized(size_t length, char*& buffer) { if (!length) return theEmptyStringImpl(); @@ -89,7 +89,7 @@ RetainPtr StringImpl::toLowercase() const if (!m_length) return const_cast(this); - for (unsigned i = 0; i < m_length; ++i) { + for (size_t i = 0; i < m_length; ++i) { if (!isASCIILowercase(m_characters[i])) goto slowPath; } @@ -98,9 +98,8 @@ RetainPtr StringImpl::toLowercase() const slowPath: char* buffer; auto lowercased = createUninitialized(m_length, buffer); - for (unsigned i = 0; i < m_length; ++i) { + for (size_t i = 0; i < m_length; ++i) buffer[i] = toASCIILowercase(m_characters[i]); - } return lowercased; } @@ -110,7 +109,7 @@ RetainPtr StringImpl::toUppercase() const if (!m_length) return const_cast(this); - for (unsigned i = 0; i < m_length; ++i) { + for (size_t i = 0; i < m_length; ++i) { if (!isASCIIUppercase(m_characters[i])) goto slowPath; } @@ -119,9 +118,8 @@ RetainPtr StringImpl::toUppercase() const slowPath: char* buffer; auto uppercased = createUninitialized(m_length, buffer); - for (unsigned i = 0; i < m_length; ++i) { + for (size_t i = 0; i < m_length; ++i) buffer[i] = toASCIIUppercase(m_characters[i]); - } return uppercased; } @@ -132,7 +130,7 @@ void StringImpl::computeHash() const m_hash = 0; } else { unsigned hash = 0; - for (unsigned i = 0; i < m_length; ++i) { + for (size_t i = 0; i < m_length; ++i) { hash += m_characters[i]; hash += (hash << 10); hash ^= (hash >> 6); diff --git a/AK/StringImpl.h b/AK/StringImpl.h index 64c4f87415b..2278438f6cb 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -2,12 +2,13 @@ #include "Retainable.h" #include "RetainPtr.h" +#include "Types.h" namespace AK { class StringImpl : public Retainable { public: - static RetainPtr createUninitialized(unsigned length, char*& buffer); + static RetainPtr createUninitialized(size_t length, char*& buffer); static RetainPtr create(const char* cstring); static RetainPtr create(const char* cstring, size_t length); RetainPtr toLowercase() const; @@ -17,9 +18,9 @@ public: ~StringImpl(); - unsigned length() const { return m_length; } + size_t length() const { return m_length; } const char* characters() const { return m_characters; } - char operator[](unsigned i) const { ASSERT(i < m_length); return m_characters[i]; } + char operator[](size_t i) const { ASSERT(i < m_length); return m_characters[i]; } unsigned hash() const { @@ -33,11 +34,11 @@ private: explicit StringImpl(ConstructTheEmptyStringImplTag) : m_characters("") { } enum ConstructWithInlineBufferTag { ConstructWithInlineBuffer }; - explicit StringImpl(ConstructWithInlineBufferTag, unsigned length) : m_length(length), m_characters(m_inlineBuffer) { } + explicit StringImpl(ConstructWithInlineBufferTag, size_t length) : m_length(length), m_characters(m_inlineBuffer) { } void computeHash() const; - unsigned m_length { 0 }; + size_t m_length { 0 }; bool m_ownsBuffer { true }; mutable bool m_hasHash { false }; const char* m_characters { nullptr }; diff --git a/AK/Types.h b/AK/Types.h index cd0eee2ff46..f970c128481 100644 --- a/AK/Types.h +++ b/AK/Types.h @@ -1,6 +1,10 @@ #pragma once +#ifdef SERENITY_KERNEL +#else #include +#include +#endif typedef uint8_t byte; typedef uint16_t word; @@ -15,3 +19,8 @@ typedef int64_t signed_qword; constexpr unsigned KB = 1024; constexpr unsigned MB = KB * KB; constexpr unsigned GB = KB * KB * KB; + +namespace std { +typedef decltype(nullptr) nullptr_t; +} + diff --git a/AK/Vector.h b/AK/Vector.h index 88ed35ac198..3bf78213675 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -4,9 +4,6 @@ #include "OwnPtr.h" #include "kmalloc.h" #include -#include -#include -#include namespace AK { @@ -34,7 +31,7 @@ public: ASSERT(index < m_size); at(index).~T(); for (unsigned i = index + 1; i < m_size; ++i) { - new (slot(i - 1)) T(std::move(at(i))); + new (slot(i - 1)) T(move(at(i))); at(i).~T(); } @@ -63,14 +60,14 @@ public: ~Vector() { clear(); } Vector(Vector&& other) - : m_impl(std::move(other.m_impl)) + : m_impl(move(other.m_impl)) { } Vector& operator=(Vector&& other) { if (this != &other) - m_impl = std::move(other.m_impl); + m_impl = move(other.m_impl); return *this; } @@ -101,7 +98,7 @@ public: T takeLast() { ASSERT(!isEmpty()); - T value = std::move(last()); + T value = move(last()); last().~T(); --m_impl->m_size; return value; @@ -115,7 +112,7 @@ public: void append(T&& value) { ensureCapacity(size() + 1); - new (m_impl->slot(m_impl->m_size)) T(std::move(value)); + new (m_impl->slot(m_impl->m_size)) T(move(value)); ++m_impl->m_size; } @@ -135,11 +132,11 @@ public: if (m_impl) { newImpl->m_size = m_impl->m_size; for (unsigned i = 0; i < size(); ++i) { - new (newImpl->slot(i)) T(std::move(m_impl->at(i))); + new (newImpl->slot(i)) T(move(m_impl->at(i))); m_impl->at(i).~T(); } } - m_impl = std::move(newImpl); + m_impl = move(newImpl); } class Iterator { @@ -175,7 +172,7 @@ public: private: static unsigned paddedCapacity(unsigned capacity) { - return std::max(4u, capacity + (capacity / 4) + 4); + return max(4u, capacity + (capacity / 4) + 4); } OwnPtr> m_impl; diff --git a/AK/test.cpp b/AK/test.cpp index edf3c4b34df..92838cbc290 100644 --- a/AK/test.cpp +++ b/AK/test.cpp @@ -20,7 +20,12 @@ int main(int, char**) for (auto& part : parts) printf("<%s>\n", part.characters()); } - + { + String cmd = "cd"; + auto parts = cmd.split(' '); + for (auto& part : parts) + printf("<%s>\n", part.characters()); + } String empty = "";