summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-10-16 12:10:01 +0200
committerAndreas Kling <awesomekling@gmail.com>2018-10-16 12:11:27 +0200
commitfd708a4cb1b224bded754a335b42e40816609a9e (patch)
tree4b73635fa7d3ddb05cb38f52dafbeb2d217c1651
parent0c1a4e8de3285d5f7d02e8eec1b7186f0193e442 (diff)
downloadserenity-fd708a4cb1b224bded754a335b42e40816609a9e.zip
Reduce dependence on STL.
-rw-r--r--AK/ByteBuffer.h10
-rw-r--r--AK/RetainPtr.h5
-rw-r--r--AK/StdLib.h5
-rw-r--r--AK/StringImpl.cpp16
-rw-r--r--AK/StringImpl.h11
-rw-r--r--AK/Types.h9
-rw-r--r--AK/Vector.h19
-rw-r--r--AK/test.cpp7
8 files changed, 48 insertions, 34 deletions
diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h
index 51227e0b71..3147d90534 100644
--- a/AK/ByteBuffer.h
+++ b/AK/ByteBuffer.h
@@ -2,9 +2,7 @@
#include "Buffer.h"
#include "Types.h"
-#include <cstdlib>
-#include <cstring>
-#include <cstdio>
+#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<Buffer<byte>>&& impl)
- : m_impl(std::move(impl))
+ : m_impl(move(impl))
{
}
diff --git a/AK/RetainPtr.h b/AK/RetainPtr.h
index f4af4d860b..5bc6ba6287 100644
--- a/AK/RetainPtr.h
+++ b/AK/RetainPtr.h
@@ -1,7 +1,8 @@
#pragma once
-#include <cstddef>
-#include <utility>
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
namespace AK {
diff --git a/AK/StdLib.h b/AK/StdLib.h
index c23609451e..5c70559087 100644
--- a/AK/StdLib.h
+++ b/AK/StdLib.h
@@ -24,6 +24,11 @@ static inline T ceilDiv(T a, T b)
return result;
}
+template <typename T>
+T&& move(T& arg)
+{
+ return static_cast<T&&>(arg);
+}
}
diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp
index 0d7016973a..6276c20a0e 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> StringImpl::createUninitialized(unsigned length, char*& buffer)
+RetainPtr<StringImpl> StringImpl::createUninitialized(size_t length, char*& buffer)
{
if (!length)
return theEmptyStringImpl();
@@ -89,7 +89,7 @@ RetainPtr<StringImpl> StringImpl::toLowercase() const
if (!m_length)
return const_cast<StringImpl*>(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> 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> StringImpl::toUppercase() const
if (!m_length)
return const_cast<StringImpl*>(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> 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 64c4f87415..2278438f6c 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<StringImpl> {
public:
- static RetainPtr<StringImpl> createUninitialized(unsigned length, char*& buffer);
+ static RetainPtr<StringImpl> createUninitialized(size_t length, char*& buffer);
static RetainPtr<StringImpl> create(const char* cstring);
static RetainPtr<StringImpl> create(const char* cstring, size_t length);
RetainPtr<StringImpl> 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 cd0eee2ff4..f970c12848 100644
--- a/AK/Types.h
+++ b/AK/Types.h
@@ -1,6 +1,10 @@
#pragma once
+#ifdef SERENITY_KERNEL
+#else
#include <stdint.h>
+#include <sys/types.h>
+#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 88ed35ac19..3bf7821367 100644
--- a/AK/Vector.h
+++ b/AK/Vector.h
@@ -4,9 +4,6 @@
#include "OwnPtr.h"
#include "kmalloc.h"
#include <new>
-#include <stdlib.h>
-#include <stdio.h>
-#include <algorithm>
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<VectorImpl<T>> m_impl;
diff --git a/AK/test.cpp b/AK/test.cpp
index edf3c4b34d..92838cbc29 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 = "";