Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: Source/WTF/wtf/MemoryInstrumentationString.h

Issue 14238015: Move Source/WTF/wtf to Source/wtf (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef MemoryInstrumentationString_h
32 #define MemoryInstrumentationString_h
33
34 #include <wtf/MemoryInstrumentation.h>
35 #include <wtf/text/AtomicString.h>
36 #include <wtf/text/CString.h>
37 #include <wtf/text/StringBuilder.h>
38 #include <wtf/text/WTFString.h>
39
40 namespace WTF {
41
42 inline void reportMemoryUsage(const StringImpl* stringImpl, MemoryObjectInfo* me moryObjectInfo)
43 {
44 size_t selfSize = sizeof(StringImpl);
45
46 size_t length = stringImpl->length() + (stringImpl->hasTerminatingNullCharac ter() ? 1 : 0);
47 size_t bufferSize = length * (stringImpl->is8Bit() ? sizeof(LChar) : sizeof( UChar));
48 const void* buffer = stringImpl->is8Bit() ? static_cast<const void*>(stringI mpl->characters8()) : static_cast<const void*>(stringImpl->characters16());
49
50 // Count size used by internal buffer but skip strings that were constructed from literals.
51 if (stringImpl->hasInternalBuffer() && buffer == stringImpl + 1)
52 selfSize += bufferSize;
53
54 MemoryClassInfo info(memoryObjectInfo, stringImpl, 0, selfSize);
55
56 if (StringImpl* baseString = stringImpl->baseString())
57 info.addMember(baseString, "baseString", RetainingPointer);
58 else {
59 if (stringImpl->hasOwnedBuffer())
60 info.addRawBuffer(buffer, bufferSize, "char[]", "ownedBuffer");
61
62 if (stringImpl->has16BitShadow())
63 info.addRawBuffer(stringImpl->characters(), length * sizeof(UChar), "UChar[]", "16bitShadow");
64 }
65 }
66
67 inline void reportMemoryUsage(const String* string, MemoryObjectInfo* memoryObje ctInfo)
68 {
69 MemoryClassInfo info(memoryObjectInfo, string);
70 info.addMember(string->impl(), "stringImpl", RetainingPointer);
71 }
72
73 template <typename CharType> class StringBuffer;
74 template <typename CharType>
75 inline void reportMemoryUsage(const StringBuffer<CharType>* stringBuffer, Memory ObjectInfo* memoryObjectInfo)
76 {
77 MemoryClassInfo info(memoryObjectInfo, stringBuffer);
78 info.addRawBuffer(stringBuffer->characters(), sizeof(CharType) * stringBuffe r->length(), "CharType[]", "data");
79 }
80
81 inline void reportMemoryUsage(const AtomicString* atomicString, MemoryObjectInfo * memoryObjectInfo)
82 {
83 MemoryClassInfo info(memoryObjectInfo, atomicString);
84 info.addMember(atomicString->string(), "string");
85 }
86
87 inline void reportMemoryUsage(const CStringBuffer* cStringBuffer, MemoryObjectIn fo* memoryObjectInfo)
88 {
89 MemoryClassInfo info(memoryObjectInfo, cStringBuffer, 0, sizeof(*cStringBuff er) + cStringBuffer->length());
90 }
91
92 inline void reportMemoryUsage(const CString* cString, MemoryObjectInfo* memoryOb jectInfo)
93 {
94 MemoryClassInfo info(memoryObjectInfo, cString);
95 info.addMember(cString->buffer(), "buffer", RetainingPointer);
96 }
97
98 }
99
100 #endif // !defined(MemoryInstrumentationVector_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698