From 7d862dd5fc3a37093462d5ff187403c9ef680a7a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 23 Mar 2020 13:45:10 +0100 Subject: [PATCH] AK: Reduce header dependency graph of String.h String.h no longer pulls in StringView.h. We do this by moving a bunch of String functions out-of-line. --- AK/BufferStream.h | 1 + AK/Demangle.h | 3 +- AK/FileSystemPath.cpp | 7 +- AK/FlyString.cpp | 6 ++ AK/FlyString.h | 2 +- AK/IPv4Address.h | 1 + AK/String.cpp | 55 +++++++++++++++ AK/String.h | 78 +++------------------- AK/StringBuilder.cpp | 1 + AK/StringView.cpp | 13 ++++ Kernel/ACPI/ACPIParser.cpp | 1 + Kernel/ACPI/ACPIStaticParser.cpp | 1 + Kernel/ACPI/DMIDecoder.cpp | 1 + Kernel/ACPI/MultiProcessorParser.cpp | 1 + Kernel/Devices/KeyboardDevice.cpp | 1 + Kernel/Devices/PATAChannel.cpp | 3 +- Kernel/Devices/PATADiskDevice.cpp | 1 + Kernel/Devices/SB16.cpp | 1 + Kernel/DoubleBuffer.cpp | 1 + Kernel/FileSystem/Custody.cpp | 1 + Kernel/FileSystem/DevPtsFS.cpp | 1 + Kernel/FileSystem/DiskBackedFileSystem.cpp | 1 + Kernel/FileSystem/Ext2FileSystem.cpp | 1 + Kernel/FileSystem/FIFO.cpp | 1 + Kernel/FileSystem/File.cpp | 1 + Kernel/FileSystem/FileSystem.cpp | 1 + Kernel/FileSystem/Inode.cpp | 1 + Kernel/FileSystem/InodeFile.cpp | 1 + Kernel/Interrupts/APIC.cpp | 1 + Kernel/Interrupts/IOAPIC.cpp | 1 + Kernel/Interrupts/InterruptManagement.cpp | 1 + Kernel/KBuffer.h | 1 + Kernel/PCI/MMIOAccess.cpp | 1 + Kernel/Thread.h | 2 +- Kernel/Time/HPET.cpp | 1 + Kernel/VM/MemoryManager.cpp | 1 + Kernel/VM/Region.cpp | 1 + Libraries/LibELF/ELFImage.cpp | 1 + Libraries/LibELF/ELFLoader.h | 1 + 39 files changed, 122 insertions(+), 77 deletions(-) diff --git a/AK/BufferStream.h b/AK/BufferStream.h index 2e2e6bac175cdd..a106ac95b4c51c 100644 --- a/AK/BufferStream.h +++ b/AK/BufferStream.h @@ -28,6 +28,7 @@ #include #include +#include namespace AK { diff --git a/AK/Demangle.h b/AK/Demangle.h index 722c32b4773807..dbba1b6c7edbab 100644 --- a/AK/Demangle.h +++ b/AK/Demangle.h @@ -27,9 +27,10 @@ #pragma once #include +#include #ifndef BUILDING_SERENITY_TOOLCHAIN -#include +# include #endif namespace AK { diff --git a/AK/FileSystemPath.cpp b/AK/FileSystemPath.cpp index 69456cb5ed5efc..a53283510b637f 100644 --- a/AK/FileSystemPath.cpp +++ b/AK/FileSystemPath.cpp @@ -24,9 +24,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "FileSystemPath.h" -#include "StringBuilder.h" -#include "Vector.h" +#include +#include +#include +#include namespace AK { diff --git a/AK/FlyString.cpp b/AK/FlyString.cpp index 07fc58e518340e..86acdd857083ce 100644 --- a/AK/FlyString.cpp +++ b/AK/FlyString.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace AK { @@ -98,4 +99,9 @@ FlyString FlyString::to_lowercase() const return String(*m_impl).to_lowercase(); } +StringView FlyString::view() const +{ + return { characters(), length() }; +} + } diff --git a/AK/FlyString.h b/AK/FlyString.h index cef44986032357..b494bd801c17d1 100644 --- a/AK/FlyString.h +++ b/AK/FlyString.h @@ -44,7 +44,7 @@ class FlyString { const char* characters() const { return m_impl ? m_impl->characters() : nullptr; } size_t length() const { return m_impl ? m_impl->length() : 0; } - StringView view() const { return { characters(), length() }; } + StringView view() const; FlyString to_lowercase() const; diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h index 6d5dc6f53535a2..aee493035fd20b 100644 --- a/AK/IPv4Address.h +++ b/AK/IPv4Address.h @@ -30,6 +30,7 @@ #include #include #include +#include #include typedef u32 in_addr_t; diff --git a/AK/String.cpp b/AK/String.cpp index 7e751d752ca519..96d426a025a93f 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #ifndef KERNEL @@ -41,6 +42,14 @@ extern "C" char* strstr(const char* haystack, const char* needle); namespace AK { +String::String(const StringView& view) +{ + if (view.m_impl) + m_impl = *view.m_impl; + else + m_impl = StringImpl::create(view.characters_without_null_termination(), view.length()); +} + bool String::operator==(const String& other) const { if (!m_impl) @@ -341,4 +350,50 @@ String String::to_uppercase() const return m_impl->to_uppercase(); } +bool operator<(const char* characters, const String& string) +{ + if (!characters) + return !string.is_null(); + + if (string.is_null()) + return false; + + return __builtin_strcmp(characters, string.characters()) < 0; +} + +bool operator>=(const char* characters, const String& string) +{ + return !(characters < string); +} + +bool operator>(const char* characters, const String& string) +{ + if (!characters) + return !string.is_null(); + + if (string.is_null()) + return false; + + return __builtin_strcmp(characters, string.characters()) > 0; +} + +bool operator<=(const char* characters, const String& string) +{ + return !(characters > string); +} + +bool String::operator==(const char* cstring) const +{ + if (is_null()) + return !cstring; + if (!cstring) + return false; + return !__builtin_strcmp(characters(), cstring); +} + +StringView String::view() const +{ + return { characters(), length() }; +} + } diff --git a/AK/String.h b/AK/String.h index 246bd02831d828..ce7ad196e2ead1 100644 --- a/AK/String.h +++ b/AK/String.h @@ -30,7 +30,6 @@ #include #include #include -#include #include namespace AK { @@ -62,14 +61,7 @@ class String { ~String() {} String() {} - - String(const StringView& view) - { - if (view.m_impl) - m_impl = *view.m_impl; - else - m_impl = StringImpl::create(view.characters_without_null_termination(), view.length()); - } + String(const StringView&); String(const String& other) : m_impl(const_cast(other).m_impl) @@ -166,19 +158,8 @@ class String { bool operator<=(const String& other) const { return !(*this > other); } bool operator<=(const char* other) const { return !(*this > other); } - bool operator==(const char* cstring) const - { - if (is_null()) - return !cstring; - if (!cstring) - return false; - return !__builtin_strcmp(characters(), cstring); - } - - bool operator!=(const char* cstring) const - { - return !(*this == cstring); - } + bool operator==(const char* cstring) const; + bool operator!=(const char* cstring) const { return !(*this == cstring); } String isolated_copy() const; @@ -228,28 +209,12 @@ class String { static String number(long); static String number(long long); - StringView view() const - { - return { characters(), length() }; - } + StringView view() const; private: RefPtr m_impl; }; -inline bool StringView::operator==(const String& string) const -{ - if (string.is_null()) - return !m_characters; - if (!m_characters) - return false; - if (m_length != string.length()) - return false; - if (m_characters == string.characters()) - return true; - return !__builtin_memcmp(m_characters, string.characters(), m_length); -} - template<> struct Traits : public GenericTraits { static unsigned hash(const String& s) { return s.impl() ? s.impl()->hash() : 0; } @@ -260,37 +225,10 @@ struct CaseInsensitiveStringTraits : public AK::Traits { static bool equals(const String& a, const String& b) { return a.to_lowercase() == b.to_lowercase(); } }; -inline bool operator<(const char* characters, const String& string) -{ - if (!characters) - return !string.is_null(); - - if (string.is_null()) - return false; - - return __builtin_strcmp(characters, string.characters()) < 0; -} - -inline bool operator>=(const char* characters, const String& string) -{ - return !(characters < string); -} - -inline bool operator>(const char* characters, const String& string) -{ - if (!characters) - return !string.is_null(); - - if (string.is_null()) - return false; - - return __builtin_strcmp(characters, string.characters()) > 0; -} - -inline bool operator<=(const char* characters, const String& string) -{ - return !(characters > string); -} +bool operator<(const char*, const String&); +bool operator>=(const char*, const String&); +bool operator>(const char*, const String&); +bool operator<=(const char*, const String&); String escape_html_entities(const StringView& html); diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 3e83f52bcafc23..17be5972a924ba 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace AK { diff --git a/AK/StringView.cpp b/AK/StringView.cpp index e979e20fdaa8bc..f927f32211c519 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -200,4 +200,17 @@ unsigned StringView::hash() const return string_hash(characters_without_null_termination(), length()); } +bool StringView::operator==(const String& string) const +{ + if (string.is_null()) + return !m_characters; + if (!m_characters) + return false; + if (m_length != string.length()) + return false; + if (m_characters == string.characters()) + return true; + return !__builtin_memcmp(m_characters, string.characters(), m_length); +} + } diff --git a/Kernel/ACPI/ACPIParser.cpp b/Kernel/ACPI/ACPIParser.cpp index 03e68b3603304d..c17a6366b75b70 100644 --- a/Kernel/ACPI/ACPIParser.cpp +++ b/Kernel/ACPI/ACPIParser.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include namespace Kernel { diff --git a/Kernel/ACPI/ACPIStaticParser.cpp b/Kernel/ACPI/ACPIStaticParser.cpp index 488442582c8e0d..f8d1f3a90749d4 100644 --- a/Kernel/ACPI/ACPIStaticParser.cpp +++ b/Kernel/ACPI/ACPIStaticParser.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Kernel/ACPI/DMIDecoder.cpp b/Kernel/ACPI/DMIDecoder.cpp index 6f6f40cdb6df34..755e46a87b90b3 100644 --- a/Kernel/ACPI/DMIDecoder.cpp +++ b/Kernel/ACPI/DMIDecoder.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Kernel/ACPI/MultiProcessorParser.cpp b/Kernel/ACPI/MultiProcessorParser.cpp index 0b405b95b1b47a..05157a77df32c2 100644 --- a/Kernel/ACPI/MultiProcessorParser.cpp +++ b/Kernel/ACPI/MultiProcessorParser.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index 2a5f2513052013..3ee979bc28c5c9 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include diff --git a/Kernel/Devices/PATAChannel.cpp b/Kernel/Devices/PATAChannel.cpp index 7f77d048faa418..7d649ddf2b970a 100644 --- a/Kernel/Devices/PATAChannel.cpp +++ b/Kernel/Devices/PATAChannel.cpp @@ -24,9 +24,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "PATADiskDevice.h" #include +#include #include +#include #include #include #include diff --git a/Kernel/Devices/PATADiskDevice.cpp b/Kernel/Devices/PATADiskDevice.cpp index a3aeb13a75f2b6..7dcad3678b530c 100644 --- a/Kernel/Devices/PATADiskDevice.cpp +++ b/Kernel/Devices/PATADiskDevice.cpp @@ -27,6 +27,7 @@ //#define PATA_DEVICE_DEBUG #include +#include #include #include #include diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp index 0c27e24bae9956..938f37ac2a0e9b 100644 --- a/Kernel/Devices/SB16.cpp +++ b/Kernel/Devices/SB16.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include diff --git a/Kernel/DoubleBuffer.cpp b/Kernel/DoubleBuffer.cpp index 0ebac2ae532e1e..f817edb1672ab2 100644 --- a/Kernel/DoubleBuffer.cpp +++ b/Kernel/DoubleBuffer.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include namespace Kernel { diff --git a/Kernel/FileSystem/Custody.cpp b/Kernel/FileSystem/Custody.cpp index 71b5d3839351fb..7699c3ea8dbeda 100644 --- a/Kernel/FileSystem/Custody.cpp +++ b/Kernel/FileSystem/Custody.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp index f2ca0a23517f71..5bb0266b6b0261 100644 --- a/Kernel/FileSystem/DevPtsFS.cpp +++ b/Kernel/FileSystem/DevPtsFS.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include diff --git a/Kernel/FileSystem/DiskBackedFileSystem.cpp b/Kernel/FileSystem/DiskBackedFileSystem.cpp index 98233da3adc9c5..d281f935ebec27 100644 --- a/Kernel/FileSystem/DiskBackedFileSystem.cpp +++ b/Kernel/FileSystem/DiskBackedFileSystem.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index cc247457d64dd0..1e4004068d398c 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp index 586d9e4eb35270..9110968e3d6192 100644 --- a/Kernel/FileSystem/FIFO.cpp +++ b/Kernel/FileSystem/FIFO.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include diff --git a/Kernel/FileSystem/File.cpp b/Kernel/FileSystem/File.cpp index 8903220809528f..85d0de5a71dca4 100644 --- a/Kernel/FileSystem/File.cpp +++ b/Kernel/FileSystem/File.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include diff --git a/Kernel/FileSystem/FileSystem.cpp b/Kernel/FileSystem/FileSystem.cpp index eaa0a3ea4983fb..021da73153b1ce 100644 --- a/Kernel/FileSystem/FileSystem.cpp +++ b/Kernel/FileSystem/FileSystem.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index a31d4abd22e93d..aa67d33cf434e4 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 399ae4a11ae744..9b12c18c7649ad 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Kernel/Interrupts/APIC.cpp b/Kernel/Interrupts/APIC.cpp index 6bf3a1aacb556a..67c25db8783458 100644 --- a/Kernel/Interrupts/APIC.cpp +++ b/Kernel/Interrupts/APIC.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include diff --git a/Kernel/Interrupts/IOAPIC.cpp b/Kernel/Interrupts/IOAPIC.cpp index c1cb1d495bc12a..0bf77069e76bdd 100644 --- a/Kernel/Interrupts/IOAPIC.cpp +++ b/Kernel/Interrupts/IOAPIC.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Kernel/Interrupts/InterruptManagement.cpp b/Kernel/Interrupts/InterruptManagement.cpp index 7ae979e0343fc4..154a1a9ce45fe2 100644 --- a/Kernel/Interrupts/InterruptManagement.cpp +++ b/Kernel/Interrupts/InterruptManagement.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include diff --git a/Kernel/KBuffer.h b/Kernel/KBuffer.h index f5cd6aedf26829..6e035186074585 100644 --- a/Kernel/KBuffer.h +++ b/Kernel/KBuffer.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include diff --git a/Kernel/PCI/MMIOAccess.cpp b/Kernel/PCI/MMIOAccess.cpp index 7606c9b6f013d2..ae3b3ca751d3c2 100644 --- a/Kernel/PCI/MMIOAccess.cpp +++ b/Kernel/PCI/MMIOAccess.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 1d0e9e0e50eb25..aeebdc462fffff 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -100,7 +100,7 @@ class Thread { Vector raw_backtrace(FlatPtr ebp) const; const String& name() const { return m_name; } - void set_name(StringView s) { m_name = s; } + void set_name(const StringView& s) { m_name = s; } void finalize(); diff --git a/Kernel/Time/HPET.cpp b/Kernel/Time/HPET.cpp index ffac283411714e..e7d082780c24ff 100644 --- a/Kernel/Time/HPET.cpp +++ b/Kernel/Time/HPET.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index b03f1fe1bcbc4e..4ee2a19e58763d 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -28,6 +28,7 @@ #include "Process.h" #include #include +#include #include #include #include diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 6caf5a24da3d91..2320ef6ea0c13a 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include diff --git a/Libraries/LibELF/ELFImage.cpp b/Libraries/LibELF/ELFImage.cpp index 6344639c877ab8..815b272561f85e 100644 --- a/Libraries/LibELF/ELFImage.cpp +++ b/Libraries/LibELF/ELFImage.cpp @@ -26,6 +26,7 @@ #include #include +#include #include ELFImage::ELFImage(const u8* buffer, size_t size) diff --git a/Libraries/LibELF/ELFLoader.h b/Libraries/LibELF/ELFLoader.h index 1331dd27111871..f0e51bc8ea60aa 100644 --- a/Libraries/LibELF/ELFLoader.h +++ b/Libraries/LibELF/ELFLoader.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include