diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 12eceeeef7e..7b005501142 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -1,6 +1,21 @@ #include "StringImpl.h" #include "StdLibExtras.h" #include "kmalloc.h" +#include "HashTable.h" + +#ifdef DEBUG_STRINGIMPL +unsigned g_stringimpl_count; +static HashTable* g_all_live_stringimpls; + +void dump_all_stringimpls() +{ + unsigned i = 0; + for (auto& it : *g_all_live_stringimpls) { + dbgprintf("%u: \"%s\"\n", i, (*it).characters()); + ++i; + } +} +#endif namespace AK { @@ -9,6 +24,10 @@ static StringImpl* s_the_empty_stringimpl = nullptr; void StringImpl::initialize_globals() { s_the_empty_stringimpl = nullptr; +#ifdef DEBUG_STRINGIMPL + g_stringimpl_count = 0; + g_all_live_stringimpls = new HashTable; +#endif } StringImpl& StringImpl::the_empty_stringimpl() @@ -18,8 +37,22 @@ StringImpl& StringImpl::the_empty_stringimpl() return *s_the_empty_stringimpl; } +StringImpl::StringImpl(ConstructWithInlineBufferTag, size_t length) + : m_length(length) + , m_characters(m_inline_buffer) +{ +#ifdef DEBUG_STRINGIMPL + ++g_stringimpl_count; + g_all_live_stringimpls->set(this); +#endif +} + StringImpl::~StringImpl() { +#ifdef DEBUG_STRINGIMPL + --g_stringimpl_count; + g_all_live_stringimpls->remove(this); +#endif } static inline size_t allocationSizeForStringImpl(size_t length) diff --git a/AK/StringImpl.h b/AK/StringImpl.h index 6a92856a9aa..8b916e42a70 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -37,7 +37,7 @@ private: explicit StringImpl(ConstructTheEmptyStringImplTag) : m_characters("") { } enum ConstructWithInlineBufferTag { ConstructWithInlineBuffer }; - explicit StringImpl(ConstructWithInlineBufferTag, size_t length) : m_length(length), m_characters(m_inline_buffer) { } + StringImpl(ConstructWithInlineBufferTag, size_t length); void compute_hash() const; diff --git a/VirtualFileSystem/SyntheticFileSystem.cpp b/VirtualFileSystem/SyntheticFileSystem.cpp index 9be72776846..3a353eeb586 100644 --- a/VirtualFileSystem/SyntheticFileSystem.cpp +++ b/VirtualFileSystem/SyntheticFileSystem.cpp @@ -116,8 +116,12 @@ bool SynthFS::remove_file(InodeIndex inode) break; } + Vector indices_to_remove; + indices_to_remove.ensureCapacity(file.m_children.size()); for (auto& child : file.m_children) - remove_file(child->m_metadata.inode.index()); + indices_to_remove.unchecked_append(child->m_metadata.inode.index()); + for (auto& index : indices_to_remove) + remove_file(index); m_inodes.remove(inode); return true; }