summaryrefslogtreecommitdiff
path: root/Source/WTF/wtf/text/StringImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WTF/wtf/text/StringImpl.cpp')
-rw-r--r--Source/WTF/wtf/text/StringImpl.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/Source/WTF/wtf/text/StringImpl.cpp b/Source/WTF/wtf/text/StringImpl.cpp
index a29263218..c06a966e7 100644
--- a/Source/WTF/wtf/text/StringImpl.cpp
+++ b/Source/WTF/wtf/text/StringImpl.cpp
@@ -28,6 +28,7 @@
#include "AtomicString.h"
#include "StringBuffer.h"
#include "StringHash.h"
+#include <wtf/MemoryInstrumentation.h>
#include <wtf/StdLibExtras.h>
#include <wtf/WTFThreadData.h>
#include <wtf/unicode/CharacterNames.h>
@@ -1791,4 +1792,24 @@ size_t StringImpl::sizeInBytes() const
return size + sizeof(*this);
}
+void StringImpl::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+{
+ size_t selfSize = sizeof(StringImpl);
+
+ // Count size used by internal buffer but skip strings that were constructed from literals.
+ if ((m_hashAndFlags & BufferInternal) && !hasTerminatingNullCharacter())
+ // Three cases are covered here:
+ // 1) a normal 8-bit string with internal storage (BufferInternal)
+ // 2) a normal 16-bit string with internal storage (BufferInternal)
+ // 3) empty unique string with length = 0 (BufferInternal)
+ selfSize += m_length * (m_hashAndFlags & s_hashFlag8BitBuffer ? sizeof(LChar) : sizeof(UChar));
+
+ MemoryClassInfo info(memoryObjectInfo, this, 0, selfSize);
+
+ if (m_hashAndFlags & BufferSubstring)
+ info.addMember(m_substringBuffer);
+ else if (m_hashAndFlags & s_hashFlagHas16BitShadow) // Substring never has its own shadow.
+ info.addRawBuffer(m_copyData16, (m_length + (hasTerminatingNullCharacter() ? 1 : 0)) * sizeof(UChar));
+}
+
} // namespace WTF