mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00
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.
This commit is contained in:
parent
1dd71bd68f
commit
7d862dd5fc
39 changed files with 122 additions and 77 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
|
|
@ -27,9 +27,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
#ifndef BUILDING_SERENITY_TOOLCHAIN
|
||||
#include <cxxabi.h>
|
||||
# include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
namespace AK {
|
||||
|
|
|
@ -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 <AK/FileSystemPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <AK/HashTable.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringUtils.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -98,4 +99,9 @@ FlyString FlyString::to_lowercase() const
|
|||
return String(*m_impl).to_lowercase();
|
||||
}
|
||||
|
||||
StringView FlyString::view() const
|
||||
{
|
||||
return { characters(), length() };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
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;
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <AK/NetworkOrdered.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
typedef u32 in_addr_t;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
#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() };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
78
AK/String.h
78
AK/String.h
|
@ -30,7 +30,6 @@
|
|||
#include <AK/RefPtr.h>
|
||||
#include <AK/StringImpl.h>
|
||||
#include <AK/StringUtils.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Traits.h>
|
||||
|
||||
namespace AK {
|
||||
|
@ -62,14 +61,7 @@ public:
|
|||
~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<String&>(other).m_impl)
|
||||
|
@ -166,19 +158,8 @@ public:
|
|||
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 @@ public:
|
|||
static String number(long);
|
||||
static String number(long long);
|
||||
|
||||
StringView view() const
|
||||
{
|
||||
return { characters(), length() };
|
||||
}
|
||||
StringView view() const;
|
||||
|
||||
private:
|
||||
RefPtr<StringImpl> 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<String> : public GenericTraits<String> {
|
||||
static unsigned hash(const String& s) { return s.impl() ? s.impl()->hash() : 0; }
|
||||
|
@ -260,37 +225,10 @@ struct CaseInsensitiveStringTraits : public AK::Traits<String> {
|
|||
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);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/ACPI/ACPIParser.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/ACPI/ACPIStaticParser.h>
|
||||
#include <Kernel/PCI/Access.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/ACPI/DMIDecoder.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <LibBareMetal/StdLib.h>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/ACPI/MultiProcessorParser.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <LibBareMetal/StdLib.h>
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/Devices/KeyboardDevice.h>
|
||||
|
|
|
@ -24,9 +24,10 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "PATADiskDevice.h"
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Devices/PATAChannel.h>
|
||||
#include <Kernel/Devices/PATADiskDevice.h>
|
||||
#include <Kernel/FileSystem/ProcFS.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
//#define PATA_DEVICE_DEBUG
|
||||
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Devices/PATAChannel.h>
|
||||
#include <Kernel/Devices/PATADiskDevice.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Devices/SB16.h>
|
||||
#include <Kernel/Thread.h>
|
||||
#include <Kernel/VM/AnonymousVMObject.h>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/DoubleBuffer.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/TTY/SlavePTY.h>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/Devices/BlockDevice.h>
|
||||
#include <Kernel/FileSystem/DiskBackedFileSystem.h>
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <AK/BufferStream.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Devices/BlockDevice.h>
|
||||
#include <Kernel/FileSystem/Ext2FileSystem.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/FIFO.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/Lock.h>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/File.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/Net/LocalSocket.h>
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/FileSystem/InodeWatcher.h>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/FileSystem/InodeFile.h>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/Interrupts/APIC.h>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/ACPI/MultiProcessorParser.h>
|
||||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/Interrupts/APIC.h>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/FixedArray.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/ACPI/MultiProcessorParser.h>
|
||||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/Interrupts/APIC.h>
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/LogStream.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <Kernel/VM/Region.h>
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/PCI/MMIOAccess.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ public:
|
|||
Vector<FlatPtr> 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();
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/ACPI/ACPIParser.h>
|
||||
#include <Kernel/Interrupts/InterruptManagement.h>
|
||||
#include <Kernel/Time/HPET.h>
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "Process.h"
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/Multiboot.h>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Thread.h>
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibELF/ELFImage.h>
|
||||
|
||||
ELFImage::ELFImage(const u8* buffer, size_t size)
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <AK/Function.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibELF/ELFImage.h>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue