From 3bbf4610d24c0dd8f8f1d0b962259c1f7e067a2d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 14 Feb 2020 21:41:10 +0100 Subject: [PATCH] AK: Add a forward declaration header You can now #include to get most of the AK types as forward declarations. Header dependency explosion is one of the main contributors to compile times at the moment, so this is a step towards smaller include graphs. --- AK/FileSystemPath.h | 1 + AK/Forward.h | 109 +++++++++++++++++++++++ AK/IPv4Address.h | 3 +- AK/JsonValue.h | 5 +- AK/LogStream.cpp | 6 ++ AK/LogStream.h | 6 +- AK/String.cpp | 4 +- AK/String.h | 3 +- AK/StringBuilder.cpp | 7 +- AK/StringBuilder.h | 7 +- AK/StringView.cpp | 2 + AK/StringView.h | 7 +- AK/Utf8View.cpp | 3 +- AK/Vector.h | 6 +- Applications/HexEditor/HexEditor.h | 3 +- Libraries/LibC/grp.cpp | 1 + Libraries/LibC/pwd.cpp | 1 + Libraries/LibC/syslog.cpp | 1 + Libraries/LibELF/ELFDynamicLoader.h | 10 +-- Libraries/LibELF/ELFDynamicObject.cpp | 6 +- Libraries/LibELF/ELFDynamicObject.h | 1 + Libraries/LibGUI/ProgressBar.cpp | 1 + Libraries/LibGUI/ScrollBar.cpp | 10 ++- Libraries/LibGUI/Shortcut.cpp | 1 + Libraries/LibGfx/PNGLoader.cpp | 1 + Libraries/LibGfx/Painter.h | 9 +- Libraries/LibGfx/Rect.cpp | 3 +- Libraries/LibHTML/CSS/StyleDeclaration.h | 1 + Libraries/LibHTML/CSS/StyleValue.cpp | 1 + Libraries/LibHTML/DOM/HTMLImageElement.h | 1 + Libraries/LibIPC/Message.h | 2 +- Libraries/LibMarkdown/MDBlock.h | 2 +- Servers/LookupServer/DNSRequest.h | 3 +- Servers/ProtocolServer/Download.h | 1 + Userland/chown.cpp | 3 +- 35 files changed, 178 insertions(+), 53 deletions(-) create mode 100644 AK/Forward.h diff --git a/AK/FileSystemPath.h b/AK/FileSystemPath.h index 4cf257dbdc6..9400292c67d 100644 --- a/AK/FileSystemPath.h +++ b/AK/FileSystemPath.h @@ -27,6 +27,7 @@ #pragma once #include +#include namespace AK { diff --git a/AK/Forward.h b/AK/Forward.h new file mode 100644 index 00000000000..e1b66768f1c --- /dev/null +++ b/AK/Forward.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +namespace AK { + +class Bitmap; +class ByteBuffer; +class IPv4Address; +class JsonArray; +class JsonObject; +class JsonValue; +class String; +class StringBuilder; +class StringImpl; +class StringView; +class URL; + +template +class SinglyLinkedList; + +template +class DoublyLinkedList; + +template +class InlineLinkedList; + +template +class CircularQueue; + +template +class Badge; + +template +class FixedArray; + +template +class Function; + +template +class Function; + +template +class NonnullRefPtr; + +template +class NonnullOwnPtr; + +template +class RefPtr; + +template +class OwnPtr; + +template +class WeakPtr; + +template +class Vector; + +} + +using AK::Badge; +using AK::Bitmap; +using AK::ByteBuffer; +using AK::CircularQueue; +using AK::DoublyLinkedList; +using AK::FixedArray; +using AK::Function; +using AK::InlineLinkedList; +using AK::IPv4Address; +using AK::JsonArray; +using AK::JsonObject; +using AK::JsonValue; +using AK::NonnullOwnPtr; +using AK::NonnullRefPtr; +using AK::OwnPtr; +using AK::RefPtr; +using AK::SinglyLinkedList; +using AK::String; +using AK::StringBuilder; +using AK::StringImpl; +using AK::StringView; +using AK::URL; +using AK::Vector; diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h index be729938e23..6d5dc6f5353 100644 --- a/AK/IPv4Address.h +++ b/AK/IPv4Address.h @@ -26,10 +26,11 @@ #pragma once -#include #include #include #include +#include +#include typedef u32 in_addr_t; diff --git a/AK/JsonValue.h b/AK/JsonValue.h index a109b671bee..c0780e331c7 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -26,6 +26,7 @@ #pragma once +#include #include #include #include @@ -33,10 +34,6 @@ namespace AK { -class JsonArray; -class JsonObject; -class StringBuilder; - class JsonValue { public: enum class Type { diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp index b6d2b5396d8..c6702fea6cb 100644 --- a/AK/LogStream.cpp +++ b/AK/LogStream.cpp @@ -112,4 +112,10 @@ DebugLogStream dbg() return stream; } +DebugLogStream::~DebugLogStream() +{ + char newline = '\n'; + write(&newline, 1); +} + } diff --git a/AK/LogStream.h b/AK/LogStream.h index 6cf7b45ddd2..8e00ad278df 100644 --- a/AK/LogStream.h +++ b/AK/LogStream.h @@ -62,11 +62,7 @@ private: class DebugLogStream final : public LogStream { public: DebugLogStream() {} - virtual ~DebugLogStream() override - { - char newline = '\n'; - write(&newline, 1); - } + virtual ~DebugLogStream() override; virtual void write(const char* characters, int length) const override { diff --git a/AK/String.cpp b/AK/String.cpp index 4e064b8070d..4149a15467e 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -27,10 +27,10 @@ #include #include #include -#include +#include #ifndef KERNEL -#include +# include #endif #ifdef KERNEL diff --git a/AK/String.h b/AK/String.h index 71c4a48293c..fea82b40b00 100644 --- a/AK/String.h +++ b/AK/String.h @@ -26,12 +26,11 @@ #pragma once -#include +#include #include #include #include #include -#include namespace AK { diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index e60f1c88267..da97a970c86 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include namespace AK { @@ -96,6 +96,11 @@ String StringBuilder::to_string() return String((const char*)m_buffer.data(), m_length); } +String StringBuilder::build() +{ + return to_string(); +} + StringView StringBuilder::string_view() const { return StringView { (const char*)m_buffer.data(), m_length }; diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index de99291bf50..1ffa801ddd3 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -26,8 +26,8 @@ #pragma once -#include -#include +#include +#include #include namespace AK { @@ -45,8 +45,7 @@ public: void appendf(const char*, ...); void appendvf(const char*, va_list); - String build() { return to_string(); } - + String build(); String to_string(); ByteBuffer to_byte_buffer(); diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 7082b608d74..69657e78cde 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -24,8 +24,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include +#include namespace AK { diff --git a/AK/StringView.h b/AK/StringView.h index 6eab64ceec4..4bf12a53644 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -26,14 +26,11 @@ #pragma once -#include +#include +#include namespace AK { -class ByteBuffer; -class String; -class StringImpl; - class StringView { public: StringView() {} diff --git a/AK/Utf8View.cpp b/AK/Utf8View.cpp index 847bef01f74..885721f7e98 100644 --- a/AK/Utf8View.cpp +++ b/AK/Utf8View.cpp @@ -24,8 +24,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include +#include namespace AK { diff --git a/AK/Vector.h b/AK/Vector.h index ed8b02b576c..f8d003e6cd0 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -27,6 +27,7 @@ #pragma once #include +#include #include #include #include @@ -44,9 +45,6 @@ namespace AK { -template -class Vector; - template class VectorIterator { public: @@ -132,7 +130,7 @@ public: } }; -template +template class Vector { public: Vector() diff --git a/Applications/HexEditor/HexEditor.h b/Applications/HexEditor/HexEditor.h index 42adcb105e8..9e1ce1f7136 100644 --- a/Applications/HexEditor/HexEditor.h +++ b/Applications/HexEditor/HexEditor.h @@ -26,13 +26,14 @@ #pragma once +#include #include #include #include #include #include -#include #include +#include class HexEditor : public GUI::ScrollableWidget { C_OBJECT(HexEditor) diff --git a/Libraries/LibC/grp.cpp b/Libraries/LibC/grp.cpp index 21d4a736501..4b0726875d0 100644 --- a/Libraries/LibC/grp.cpp +++ b/Libraries/LibC/grp.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include diff --git a/Libraries/LibC/pwd.cpp b/Libraries/LibC/pwd.cpp index 794438a51f5..00bf40476e7 100644 --- a/Libraries/LibC/pwd.cpp +++ b/Libraries/LibC/pwd.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include diff --git a/Libraries/LibC/syslog.cpp b/Libraries/LibC/syslog.cpp index 180eb22fdeb..650347da967 100644 --- a/Libraries/LibC/syslog.cpp +++ b/Libraries/LibC/syslog.cpp @@ -27,6 +27,7 @@ // Has to be defined before including due to legacy Unices #define SYSLOG_NAMES 1 +#include #include #include #include diff --git a/Libraries/LibELF/ELFDynamicLoader.h b/Libraries/LibELF/ELFDynamicLoader.h index e5cc508e892..c3932714d48 100644 --- a/Libraries/LibELF/ELFDynamicLoader.h +++ b/Libraries/LibELF/ELFDynamicLoader.h @@ -26,14 +26,14 @@ #pragma once -#include -#include -#include -#include - +#include #include #include #include +#include +#include +#include +#include #define ALIGN_ROUND_UP(x, align) ((((size_t)(x)) + align - 1) & (~(align - 1))) diff --git a/Libraries/LibELF/ELFDynamicObject.cpp b/Libraries/LibELF/ELFDynamicObject.cpp index 0e8aafaf916..5a98a0ae043 100644 --- a/Libraries/LibELF/ELFDynamicObject.cpp +++ b/Libraries/LibELF/ELFDynamicObject.cpp @@ -24,12 +24,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include #include #include - -#include - -#include #include static const char* name_for_dtag(Elf32_Sword d_tag); diff --git a/Libraries/LibELF/ELFDynamicObject.h b/Libraries/LibELF/ELFDynamicObject.h index 5e88f2665d6..80eb9db281b 100644 --- a/Libraries/LibELF/ELFDynamicObject.h +++ b/Libraries/LibELF/ELFDynamicObject.h @@ -26,6 +26,7 @@ #pragma once +#include #include #include diff --git a/Libraries/LibGUI/ProgressBar.cpp b/Libraries/LibGUI/ProgressBar.cpp index 4e55e3720b2..b957a159c1b 100644 --- a/Libraries/LibGUI/ProgressBar.cpp +++ b/Libraries/LibGUI/ProgressBar.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Libraries/LibGUI/ScrollBar.cpp b/Libraries/LibGUI/ScrollBar.cpp index c50f3fb7b40..27c3531ad96 100644 --- a/Libraries/LibGUI/ScrollBar.cpp +++ b/Libraries/LibGUI/ScrollBar.cpp @@ -24,12 +24,14 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include -#include +#include +#include #include #include +#include +#include +#include +#include namespace GUI { diff --git a/Libraries/LibGUI/Shortcut.cpp b/Libraries/LibGUI/Shortcut.cpp index 37fa479450a..cc76d78a759 100644 --- a/Libraries/LibGUI/Shortcut.cpp +++ b/Libraries/LibGUI/Shortcut.cpp @@ -25,6 +25,7 @@ */ #include +#include #include namespace GUI { diff --git a/Libraries/LibGfx/PNGLoader.cpp b/Libraries/LibGfx/PNGLoader.cpp index 0b293dbac7d..863c63d8067 100644 --- a/Libraries/LibGfx/PNGLoader.cpp +++ b/Libraries/LibGfx/PNGLoader.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Libraries/LibGfx/Painter.h b/Libraries/LibGfx/Painter.h index 7e8cfb838f2..1775c1b3d2f 100644 --- a/Libraries/LibGfx/Painter.h +++ b/Libraries/LibGfx/Painter.h @@ -26,12 +26,13 @@ #pragma once -#include "Color.h" -#include "Point.h" -#include "Rect.h" -#include "Size.h" #include #include +#include +#include +#include +#include +#include #include #include diff --git a/Libraries/LibGfx/Rect.cpp b/Libraries/LibGfx/Rect.cpp index bff5d90ae31..af663bfc092 100644 --- a/Libraries/LibGfx/Rect.cpp +++ b/Libraries/LibGfx/Rect.cpp @@ -24,8 +24,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "Rect.h" #include +#include +#include namespace Gfx { diff --git a/Libraries/LibHTML/CSS/StyleDeclaration.h b/Libraries/LibHTML/CSS/StyleDeclaration.h index 52a0e8ddc7b..ebe8a6d3ca8 100644 --- a/Libraries/LibHTML/CSS/StyleDeclaration.h +++ b/Libraries/LibHTML/CSS/StyleDeclaration.h @@ -27,6 +27,7 @@ #pragma once #include +#include #include struct StyleProperty { diff --git a/Libraries/LibHTML/CSS/StyleValue.cpp b/Libraries/LibHTML/CSS/StyleValue.cpp index 591e8bdcaa3..0a19807c811 100644 --- a/Libraries/LibHTML/CSS/StyleValue.cpp +++ b/Libraries/LibHTML/CSS/StyleValue.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.h b/Libraries/LibHTML/DOM/HTMLImageElement.h index 7035b1706d5..345c32665c3 100644 --- a/Libraries/LibHTML/DOM/HTMLImageElement.h +++ b/Libraries/LibHTML/DOM/HTMLImageElement.h @@ -26,6 +26,7 @@ #pragma once +#include #include #include #include diff --git a/Libraries/LibIPC/Message.h b/Libraries/LibIPC/Message.h index a8f4bccd5b2..73dc9c689d0 100644 --- a/Libraries/LibIPC/Message.h +++ b/Libraries/LibIPC/Message.h @@ -26,7 +26,7 @@ #pragma once -#include +#include namespace IPC { diff --git a/Libraries/LibMarkdown/MDBlock.h b/Libraries/LibMarkdown/MDBlock.h index b22265f4228..facceb359ae 100644 --- a/Libraries/LibMarkdown/MDBlock.h +++ b/Libraries/LibMarkdown/MDBlock.h @@ -26,7 +26,7 @@ #pragma once -#include +#include class MDBlock { public: diff --git a/Servers/LookupServer/DNSRequest.h b/Servers/LookupServer/DNSRequest.h index ae42a0fe35e..2b55dd75fbc 100644 --- a/Servers/LookupServer/DNSRequest.h +++ b/Servers/LookupServer/DNSRequest.h @@ -27,9 +27,8 @@ #pragma once #include "DNSQuestion.h" -#include -#include #include +#include #define T_A 1 #define T_NS 2 diff --git a/Servers/ProtocolServer/Download.h b/Servers/ProtocolServer/Download.h index 360e407c476..4653d69eab5 100644 --- a/Servers/ProtocolServer/Download.h +++ b/Servers/ProtocolServer/Download.h @@ -26,6 +26,7 @@ #pragma once +#include #include #include #include diff --git a/Userland/chown.cpp b/Userland/chown.cpp index d5009dff244..54202c2f72a 100644 --- a/Userland/chown.cpp +++ b/Userland/chown.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -69,7 +70,7 @@ int main(int argc, char** argv) if (!ok) { new_gid = getgrnam(parts[1].characters())->gr_gid; - if(!new_gid) { + if (!new_gid) { fprintf(stderr, "Invalid gid: '%s'\n", parts[1].characters()); return 1; }