File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 15
15
#include < map>
16
16
#include < memory>
17
17
#include < set>
18
+ #include < string>
18
19
#include < vector>
19
20
#include < unordered_map>
20
21
#include < unordered_set>
@@ -90,6 +91,18 @@ static inline size_t DynamicUsage(const std::vector<T, Allocator>& v)
90
91
return MallocUsage (v.capacity () * sizeof (T));
91
92
}
92
93
94
+ static inline size_t DynamicUsage (const std::string& s)
95
+ {
96
+ const char * s_ptr = reinterpret_cast <const char *>(&s);
97
+ // Don't count the dynamic memory used for string, if it resides in the
98
+ // "small string" optimization area (which stores data inside the object itself, up to some
99
+ // size; 15 bytes in modern libstdc++).
100
+ if (!std::less{}(s.data (), s_ptr) && !std::greater{}(s.data () + s.size (), s_ptr + sizeof (s))) {
101
+ return 0 ;
102
+ }
103
+ return MallocUsage (s.capacity ());
104
+ }
105
+
93
106
template <unsigned int N, typename X, typename S, typename D>
94
107
static inline size_t DynamicUsage (const prevector<N, X, S, D>& v)
95
108
{
You can’t perform that action at this time.
0 commit comments