/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Core/UniqueCStringMap.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- UniqueCStringMap.h --------------------------------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #ifndef LLDB_CORE_UNIQUECSTRINGMAP_H |
10 | | #define LLDB_CORE_UNIQUECSTRINGMAP_H |
11 | | |
12 | | #include <algorithm> |
13 | | #include <vector> |
14 | | |
15 | | #include "lldb/Utility/ConstString.h" |
16 | | #include "lldb/Utility/RegularExpression.h" |
17 | | |
18 | | namespace lldb_private { |
19 | | |
20 | | // Templatized uniqued string map. |
21 | | // |
22 | | // This map is useful for mapping unique C string names to values of type T. |
23 | | // Each "const char *" name added must be unique for a given |
24 | | // C string value. ConstString::GetCString() can provide such strings. |
25 | | // Any other string table that has guaranteed unique values can also be used. |
26 | | template <typename T> class UniqueCStringMap { |
27 | | public: |
28 | | struct Entry { |
29 | 156M | Entry(ConstString cstr, const T &v) : cstring(cstr), value(333k v155M ) {} lldb_private::UniqueCStringMap<unsigned int>::Entry::Entry(lldb_private::ConstString, unsigned int const&) Line | Count | Source | 29 | 155M | Entry(ConstString cstr, const T &v) : cstring(cstr), value(v) {} |
lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Entry::Entry(lldb_private::ConstString, lldb_private::OptionValueEnumeration::EnumeratorInfo const&) Line | Count | Source | 29 | 237k | Entry(ConstString cstr, const T &v) : cstring(cstr), value(v) {} |
lldb_private::UniqueCStringMap<DWARFDIE>::Entry::Entry(lldb_private::ConstString, DWARFDIE const&) Line | Count | Source | 29 | 16 | Entry(ConstString cstr, const T &v) : cstring(cstr), value(v) {} |
lldb_private::UniqueCStringMap<DIERef>::Entry::Entry(lldb_private::ConstString, DIERef const&) Line | Count | Source | 29 | 95.2k | Entry(ConstString cstr, const T &v) : cstring(cstr), value(v) {} |
|
30 | | |
31 | | ConstString cstring; |
32 | | T value; |
33 | | }; |
34 | | |
35 | | typedef std::vector<Entry> collection; |
36 | | typedef typename collection::iterator iterator; |
37 | | typedef typename collection::const_iterator const_iterator; |
38 | | |
39 | | // Call this function multiple times to add a bunch of entries to this map, |
40 | | // then later call UniqueCStringMap<T>::Sort() before doing any searches by |
41 | | // name. |
42 | 135M | void Append(ConstString unique_cstr, const T &value) { |
43 | 135M | m_map.push_back(typename UniqueCStringMap<T>::Entry(unique_cstr, value)); |
44 | 135M | } lldb_private::UniqueCStringMap<unsigned int>::Append(lldb_private::ConstString, unsigned int const&) Line | Count | Source | 42 | 135M | void Append(ConstString unique_cstr, const T &value) { | 43 | 135M | m_map.push_back(typename UniqueCStringMap<T>::Entry(unique_cstr, value)); | 44 | 135M | } |
lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Append(lldb_private::ConstString, lldb_private::OptionValueEnumeration::EnumeratorInfo const&) Line | Count | Source | 42 | 237k | void Append(ConstString unique_cstr, const T &value) { | 43 | 237k | m_map.push_back(typename UniqueCStringMap<T>::Entry(unique_cstr, value)); | 44 | 237k | } |
lldb_private::UniqueCStringMap<DWARFDIE>::Append(lldb_private::ConstString, DWARFDIE const&) Line | Count | Source | 42 | 16 | void Append(ConstString unique_cstr, const T &value) { | 43 | 16 | m_map.push_back(typename UniqueCStringMap<T>::Entry(unique_cstr, value)); | 44 | 16 | } |
lldb_private::UniqueCStringMap<DIERef>::Append(lldb_private::ConstString, DIERef const&) Line | Count | Source | 42 | 95.2k | void Append(ConstString unique_cstr, const T &value) { | 43 | 95.2k | m_map.push_back(typename UniqueCStringMap<T>::Entry(unique_cstr, value)); | 44 | 95.2k | } |
|
45 | | |
46 | 27.5M | void Append(const Entry &e) { m_map.push_back(e); } |
47 | | |
48 | 82.6k | void Clear() { m_map.clear(); } lldb_private::UniqueCStringMap<unsigned int>::Clear() Line | Count | Source | 48 | 7.35k | void Clear() { m_map.clear(); } |
lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Clear() Line | Count | Source | 48 | 75.2k | void Clear() { m_map.clear(); } |
lldb_private::UniqueCStringMap<DIERef>::Clear() Line | Count | Source | 48 | 44 | void Clear() { m_map.clear(); } |
|
49 | | |
50 | | // Get an entries by index in a variety of forms. |
51 | | // |
52 | | // The caller is responsible for ensuring that the collection does not change |
53 | | // during while using the returned values. |
54 | | bool GetValueAtIndex(uint32_t idx, T &value) const { |
55 | | if (idx < m_map.size()) { |
56 | | value = m_map[idx].value; |
57 | | return true; |
58 | | } |
59 | | return false; |
60 | | } |
61 | | |
62 | 47.5k | ConstString GetCStringAtIndexUnchecked(uint32_t idx) const { |
63 | 47.5k | return m_map[idx].cstring; |
64 | 47.5k | } |
65 | | |
66 | | // Use this function if you have simple types in your map that you can easily |
67 | | // copy when accessing values by index. |
68 | 47.8k | T GetValueAtIndexUnchecked(uint32_t idx) const { return m_map[idx].value; } lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::GetValueAtIndexUnchecked(unsigned int) const Line | Count | Source | 68 | 229 | T GetValueAtIndexUnchecked(uint32_t idx) const { return m_map[idx].value; } |
lldb_private::UniqueCStringMap<DWARFDIE>::GetValueAtIndexUnchecked(unsigned int) const Line | Count | Source | 68 | 26 | T GetValueAtIndexUnchecked(uint32_t idx) const { return m_map[idx].value; } |
lldb_private::UniqueCStringMap<DIERef>::GetValueAtIndexUnchecked(unsigned int) const Line | Count | Source | 68 | 47.6k | T GetValueAtIndexUnchecked(uint32_t idx) const { return m_map[idx].value; } |
|
69 | | |
70 | | // Use this function if you have complex types in your map that you don't |
71 | | // want to copy when accessing values by index. |
72 | 72 | const T &GetValueRefAtIndexUnchecked(uint32_t idx) const { |
73 | 72 | return m_map[idx].value; |
74 | 72 | } |
75 | | |
76 | 200 | ConstString GetCStringAtIndex(uint32_t idx) const { |
77 | 200 | return ((idx < m_map.size()) ? m_map[idx].cstring : ConstString()0 ); |
78 | 200 | } lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::GetCStringAtIndex(unsigned int) const Line | Count | Source | 76 | 122 | ConstString GetCStringAtIndex(uint32_t idx) const { | 77 | 122 | return ((idx < m_map.size()) ? m_map[idx].cstring : ConstString()0 ); | 78 | 122 | } |
lldb_private::UniqueCStringMap<DWARFDIE>::GetCStringAtIndex(unsigned int) const Line | Count | Source | 76 | 6 | ConstString GetCStringAtIndex(uint32_t idx) const { | 77 | 6 | return ((idx < m_map.size()) ? m_map[idx].cstring : ConstString()0 ); | 78 | 6 | } |
lldb_private::UniqueCStringMap<DIERef>::GetCStringAtIndex(unsigned int) const Line | Count | Source | 76 | 72 | ConstString GetCStringAtIndex(uint32_t idx) const { | 77 | 72 | return ((idx < m_map.size()) ? m_map[idx].cstring : ConstString()0 ); | 78 | 72 | } |
|
79 | | |
80 | | // Find the value for the unique string in the map. |
81 | | // |
82 | | // Return the value for \a unique_cstr if one is found, return \a fail_value |
83 | | // otherwise. This method works well for simple type |
84 | | // T values and only if there is a sensible failure value that can |
85 | | // be returned and that won't match any existing values. |
86 | 6 | T Find(ConstString unique_cstr, T fail_value) const { |
87 | 6 | auto pos = llvm::lower_bound(m_map, unique_cstr, Compare()); |
88 | 6 | if (pos != m_map.end() && pos->cstring == unique_cstr) |
89 | 0 | return pos->value; |
90 | 6 | return fail_value; |
91 | 6 | } |
92 | | |
93 | | // Get a pointer to the first entry that matches "name". nullptr will be |
94 | | // returned if there is no entry that matches "name". |
95 | | // |
96 | | // The caller is responsible for ensuring that the collection does not change |
97 | | // during while using the returned pointer. |
98 | 1.08M | const Entry *FindFirstValueForName(ConstString unique_cstr) const { |
99 | 1.08M | auto pos = llvm::lower_bound(m_map, unique_cstr, Compare()); |
100 | 1.08M | if (pos != m_map.end() && pos->cstring == unique_cstr198k ) |
101 | 1.49k | return &(*pos); |
102 | 1.08M | return nullptr; |
103 | 1.08M | } lldb_private::UniqueCStringMap<unsigned int>::FindFirstValueForName(lldb_private::ConstString) const Line | Count | Source | 98 | 1.08M | const Entry *FindFirstValueForName(ConstString unique_cstr) const { | 99 | 1.08M | auto pos = llvm::lower_bound(m_map, unique_cstr, Compare()); | 100 | 1.08M | if (pos != m_map.end() && pos->cstring == unique_cstr198k ) | 101 | 1.04k | return &(*pos); | 102 | 1.08M | return nullptr; | 103 | 1.08M | } |
lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::FindFirstValueForName(lldb_private::ConstString) const Line | Count | Source | 98 | 442 | const Entry *FindFirstValueForName(ConstString unique_cstr) const { | 99 | 442 | auto pos = llvm::lower_bound(m_map, unique_cstr, Compare()); | 100 | 442 | if (pos != m_map.end() && pos->cstring == unique_cstr) | 101 | 442 | return &(*pos); | 102 | 0 | return nullptr; | 103 | 442 | } |
|
104 | | |
105 | | // Get a pointer to the next entry that matches "name" from a previously |
106 | | // returned Entry pointer. nullptr will be returned if there is no subsequent |
107 | | // entry that matches "name". |
108 | | // |
109 | | // The caller is responsible for ensuring that the collection does not change |
110 | | // during while using the returned pointer. |
111 | 4.07k | const Entry *FindNextValueForName(const Entry *entry_ptr) const { |
112 | 4.07k | if (!m_map.empty()) { |
113 | 4.07k | const Entry *first_entry = &m_map[0]; |
114 | 4.07k | const Entry *after_last_entry = first_entry + m_map.size(); |
115 | 4.07k | const Entry *next_entry = entry_ptr + 1; |
116 | 4.07k | if (first_entry <= next_entry && next_entry < after_last_entry) { |
117 | 3.87k | if (next_entry->cstring == entry_ptr->cstring) |
118 | 3.08k | return next_entry; |
119 | 3.87k | } |
120 | 4.07k | } |
121 | 990 | return nullptr; |
122 | 4.07k | } |
123 | | |
124 | 5.58M | size_t GetValues(ConstString unique_cstr, std::vector<T> &values) const { |
125 | 5.58M | const size_t start_size = values.size(); |
126 | | |
127 | 5.58M | for (const Entry &entry : llvm::make_range(std::equal_range( |
128 | 5.58M | m_map.begin(), m_map.end(), unique_cstr, Compare()))) |
129 | 227k | values.push_back(entry.value); |
130 | | |
131 | 5.58M | return values.size() - start_size; |
132 | 5.58M | } |
133 | | |
134 | | size_t GetValues(const RegularExpression ®ex, |
135 | 0 | std::vector<T> &values) const { |
136 | 0 | const size_t start_size = values.size(); |
137 | |
|
138 | 0 | const_iterator pos, end = m_map.end(); |
139 | 0 | for (pos = m_map.begin(); pos != end; ++pos) { |
140 | 0 | if (regex.Execute(pos->cstring.GetCString())) |
141 | 0 | values.push_back(pos->value); |
142 | 0 | } |
143 | |
|
144 | 0 | return values.size() - start_size; |
145 | 0 | } |
146 | | |
147 | | // Get the total number of entries in this map. |
148 | 37.0k | size_t GetSize() const { return m_map.size(); } lldb_private::UniqueCStringMap<unsigned int>::GetSize() const Line | Count | Source | 148 | 7 | size_t GetSize() const { return m_map.size(); } |
lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::GetSize() const Line | Count | Source | 148 | 119 | size_t GetSize() const { return m_map.size(); } |
lldb_private::UniqueCStringMap<DWARFDIE>::GetSize() const Line | Count | Source | 148 | 32 | size_t GetSize() const { return m_map.size(); } |
lldb_private::UniqueCStringMap<DIERef>::GetSize() const Line | Count | Source | 148 | 36.8k | size_t GetSize() const { return m_map.size(); } |
|
149 | | |
150 | | // Returns true if this map is empty. |
151 | 220 | bool IsEmpty() const { return m_map.empty(); } lldb_private::UniqueCStringMap<unsigned int>::IsEmpty() const Line | Count | Source | 151 | 40 | bool IsEmpty() const { return m_map.empty(); } |
lldb_private::UniqueCStringMap<DWARFDIE>::IsEmpty() const Line | Count | Source | 151 | 12 | bool IsEmpty() const { return m_map.empty(); } |
lldb_private::UniqueCStringMap<DIERef>::IsEmpty() const Line | Count | Source | 151 | 168 | bool IsEmpty() const { return m_map.empty(); } |
|
152 | | |
153 | | // Reserve memory for at least "n" entries in the map. This is useful to call |
154 | | // when you know you will be adding a lot of entries using |
155 | | // UniqueCStringMap::Append() (which should be followed by a call to |
156 | | // UniqueCStringMap::Sort()) or to UniqueCStringMap::Insert(). |
157 | 115k | void Reserve(size_t n) { m_map.reserve(n); } lldb_private::UniqueCStringMap<unsigned int>::Reserve(unsigned long) Line | Count | Source | 157 | 115k | void Reserve(size_t n) { m_map.reserve(n); } |
lldb_private::UniqueCStringMap<DIERef>::Reserve(unsigned long) Line | Count | Source | 157 | 36 | void Reserve(size_t n) { m_map.reserve(n); } |
|
158 | | |
159 | | // Sort the unsorted contents in this map. A typical code flow would be: |
160 | | // size_t approximate_num_entries = .... |
161 | | // UniqueCStringMap<uint32_t> my_map; |
162 | | // my_map.Reserve (approximate_num_entries); |
163 | | // for (...) |
164 | | // { |
165 | | // my_map.Append (UniqueCStringMap::Entry(GetName(...), GetValue(...))); |
166 | | // } |
167 | | // my_map.Sort(); |
168 | 549k | void Sort() { |
169 | 46.6M | Sort([](const T &, const T &) { return false; }); lldb_private::UniqueCStringMap<unsigned int>::Sort()::'lambda'(unsigned int const&, unsigned int const&)::operator()(unsigned int const&, unsigned int const&) const Line | Count | Source | 169 | 46.6M | Sort([](const T &, const T &) { return false; }); |
Unexecuted instantiation: lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Sort()::'lambda'(lldb_private::OptionValueEnumeration::EnumeratorInfo const&, lldb_private::OptionValueEnumeration::EnumeratorInfo const&)::operator()(lldb_private::OptionValueEnumeration::EnumeratorInfo const&, lldb_private::OptionValueEnumeration::EnumeratorInfo const&) const Unexecuted instantiation: lldb_private::UniqueCStringMap<DWARFDIE>::Sort()::'lambda'(DWARFDIE const&, DWARFDIE const&)::operator()(DWARFDIE const&, DWARFDIE const&) const |
170 | 549k | } lldb_private::UniqueCStringMap<unsigned int>::Sort() Line | Count | Source | 168 | 474k | void Sort() { | 169 | 474k | Sort([](const T &, const T &) { return false; }); | 170 | 474k | } |
lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Sort() Line | Count | Source | 168 | 75.2k | void Sort() { | 169 | 75.2k | Sort([](const T &, const T &) { return false; }); | 170 | 75.2k | } |
lldb_private::UniqueCStringMap<DWARFDIE>::Sort() Line | Count | Source | 168 | 6 | void Sort() { | 169 | 6 | Sort([](const T &, const T &) { return false; }); | 170 | 6 | } |
|
171 | | |
172 | | /// Sort contents of this map using the provided comparator to break ties for |
173 | | /// entries with the same string value. |
174 | 584k | template <typename TCompare> void Sort(TCompare tc) { |
175 | 584k | Compare c; |
176 | 2.26G | llvm::sort(m_map, [&](const Entry &lhs, const Entry &rhs) -> bool { |
177 | 2.26G | int result = c.ThreeWay(lhs.cstring, rhs.cstring); |
178 | 2.26G | if (result == 0) |
179 | 46.6M | return tc(lhs.value, rhs.value); |
180 | 2.21G | return result < 0; |
181 | 2.26G | }); void lldb_private::UniqueCStringMap<unsigned int>::Sort<lldb_private::UniqueCStringMap<unsigned int>::Sort()::'lambda'(unsigned int const&, unsigned int const&)>(lldb_private::UniqueCStringMap<unsigned int>::Sort()::'lambda'(unsigned int const&, unsigned int const&))::'lambda'(lldb_private::UniqueCStringMap<unsigned int>::Entry const&, lldb_private::UniqueCStringMap<unsigned int>::Entry const&)::operator()(lldb_private::UniqueCStringMap<unsigned int>::Entry const&, lldb_private::UniqueCStringMap<unsigned int>::Entry const&) const Line | Count | Source | 176 | 2.26G | llvm::sort(m_map, [&](const Entry &lhs, const Entry &rhs) -> bool { | 177 | 2.26G | int result = c.ThreeWay(lhs.cstring, rhs.cstring); | 178 | 2.26G | if (result == 0) | 179 | 46.6M | return tc(lhs.value, rhs.value); | 180 | 2.21G | return result < 0; | 181 | 2.26G | }); |
void lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Sort<lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Sort()::'lambda'(lldb_private::OptionValueEnumeration::EnumeratorInfo const&, lldb_private::OptionValueEnumeration::EnumeratorInfo const&)>(lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Sort()::'lambda'(lldb_private::OptionValueEnumeration::EnumeratorInfo const&, lldb_private::OptionValueEnumeration::EnumeratorInfo const&))::'lambda'(lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Entry const&, lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Entry const&)::operator()(lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Entry const&, lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Entry const&) const Line | Count | Source | 176 | 218k | llvm::sort(m_map, [&](const Entry &lhs, const Entry &rhs) -> bool { | 177 | 218k | int result = c.ThreeWay(lhs.cstring, rhs.cstring); | 178 | 218k | if (result == 0) | 179 | 0 | return tc(lhs.value, rhs.value); | 180 | 218k | return result < 0; | 181 | 218k | }); |
Unexecuted instantiation: void lldb_private::UniqueCStringMap<DWARFDIE>::Sort<lldb_private::UniqueCStringMap<DWARFDIE>::Sort()::'lambda'(DWARFDIE const&, DWARFDIE const&)>(lldb_private::UniqueCStringMap<DWARFDIE>::Sort()::'lambda'(DWARFDIE const&, DWARFDIE const&))::'lambda'(lldb_private::UniqueCStringMap<DWARFDIE>::Entry const&, lldb_private::UniqueCStringMap<DWARFDIE>::Entry const&)::operator()(lldb_private::UniqueCStringMap<DWARFDIE>::Entry const&, lldb_private::UniqueCStringMap<DWARFDIE>::Entry const&) const void lldb_private::UniqueCStringMap<DIERef>::Sort<std::__1::less<DIERef> >(std::__1::less<DIERef>)::'lambda'(lldb_private::UniqueCStringMap<DIERef>::Entry const&, lldb_private::UniqueCStringMap<DIERef>::Entry const&)::operator()(lldb_private::UniqueCStringMap<DIERef>::Entry const&, lldb_private::UniqueCStringMap<DIERef>::Entry const&) const Line | Count | Source | 176 | 162k | llvm::sort(m_map, [&](const Entry &lhs, const Entry &rhs) -> bool { | 177 | 162k | int result = c.ThreeWay(lhs.cstring, rhs.cstring); | 178 | 162k | if (result == 0) | 179 | 2.95k | return tc(lhs.value, rhs.value); | 180 | 159k | return result < 0; | 181 | 162k | }); |
|
182 | 584k | } void lldb_private::UniqueCStringMap<unsigned int>::Sort<lldb_private::UniqueCStringMap<unsigned int>::Sort()::'lambda'(unsigned int const&, unsigned int const&)>(lldb_private::UniqueCStringMap<unsigned int>::Sort()::'lambda'(unsigned int const&, unsigned int const&)) Line | Count | Source | 174 | 474k | template <typename TCompare> void Sort(TCompare tc) { | 175 | 474k | Compare c; | 176 | 474k | llvm::sort(m_map, [&](const Entry &lhs, const Entry &rhs) -> bool { | 177 | 474k | int result = c.ThreeWay(lhs.cstring, rhs.cstring); | 178 | 474k | if (result == 0) | 179 | 474k | return tc(lhs.value, rhs.value); | 180 | 474k | return result < 0; | 181 | 474k | }); | 182 | 474k | } |
void lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Sort<lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Sort()::'lambda'(lldb_private::OptionValueEnumeration::EnumeratorInfo const&, lldb_private::OptionValueEnumeration::EnumeratorInfo const&)>(lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Sort()::'lambda'(lldb_private::OptionValueEnumeration::EnumeratorInfo const&, lldb_private::OptionValueEnumeration::EnumeratorInfo const&)) Line | Count | Source | 174 | 75.2k | template <typename TCompare> void Sort(TCompare tc) { | 175 | 75.2k | Compare c; | 176 | 75.2k | llvm::sort(m_map, [&](const Entry &lhs, const Entry &rhs) -> bool { | 177 | 75.2k | int result = c.ThreeWay(lhs.cstring, rhs.cstring); | 178 | 75.2k | if (result == 0) | 179 | 75.2k | return tc(lhs.value, rhs.value); | 180 | 75.2k | return result < 0; | 181 | 75.2k | }); | 182 | 75.2k | } |
void lldb_private::UniqueCStringMap<DWARFDIE>::Sort<lldb_private::UniqueCStringMap<DWARFDIE>::Sort()::'lambda'(DWARFDIE const&, DWARFDIE const&)>(lldb_private::UniqueCStringMap<DWARFDIE>::Sort()::'lambda'(DWARFDIE const&, DWARFDIE const&)) Line | Count | Source | 174 | 6 | template <typename TCompare> void Sort(TCompare tc) { | 175 | 6 | Compare c; | 176 | 6 | llvm::sort(m_map, [&](const Entry &lhs, const Entry &rhs) -> bool { | 177 | 6 | int result = c.ThreeWay(lhs.cstring, rhs.cstring); | 178 | 6 | if (result == 0) | 179 | 6 | return tc(lhs.value, rhs.value); | 180 | 6 | return result < 0; | 181 | 6 | }); | 182 | 6 | } |
void lldb_private::UniqueCStringMap<DIERef>::Sort<std::__1::less<DIERef> >(std::__1::less<DIERef>) Line | Count | Source | 174 | 34.2k | template <typename TCompare> void Sort(TCompare tc) { | 175 | 34.2k | Compare c; | 176 | 34.2k | llvm::sort(m_map, [&](const Entry &lhs, const Entry &rhs) -> bool { | 177 | 34.2k | int result = c.ThreeWay(lhs.cstring, rhs.cstring); | 178 | 34.2k | if (result == 0) | 179 | 34.2k | return tc(lhs.value, rhs.value); | 180 | 34.2k | return result < 0; | 181 | 34.2k | }); | 182 | 34.2k | } |
|
183 | | |
184 | | // Since we are using a vector to contain our items it will always double its |
185 | | // memory consumption as things are added to the vector, so if you intend to |
186 | | // keep a UniqueCStringMap around and have a lot of entries in the map, you |
187 | | // will want to call this function to create a new vector and copy _only_ the |
188 | | // exact size needed as part of the finalization of the string map. |
189 | 495k | void SizeToFit() { |
190 | 495k | if (m_map.size() < m_map.capacity()) { |
191 | 168k | collection temp(m_map.begin(), m_map.end()); |
192 | 168k | m_map.swap(temp); |
193 | 168k | } |
194 | 495k | } lldb_private::UniqueCStringMap<unsigned int>::SizeToFit() Line | Count | Source | 189 | 461k | void SizeToFit() { | 190 | 461k | if (m_map.size() < m_map.capacity()) { | 191 | 165k | collection temp(m_map.begin(), m_map.end()); | 192 | 165k | m_map.swap(temp); | 193 | 165k | } | 194 | 461k | } |
lldb_private::UniqueCStringMap<DIERef>::SizeToFit() Line | Count | Source | 189 | 34.2k | void SizeToFit() { | 190 | 34.2k | if (m_map.size() < m_map.capacity()) { | 191 | 2.69k | collection temp(m_map.begin(), m_map.end()); | 192 | 2.69k | m_map.swap(temp); | 193 | 2.69k | } | 194 | 34.2k | } |
|
195 | | |
196 | | iterator begin() { return m_map.begin(); } |
197 | | iterator end() { return m_map.end(); } |
198 | 51 | const_iterator begin() const { return m_map.begin(); } lldb_private::UniqueCStringMap<unsigned int>::begin() const Line | Count | Source | 198 | 7 | const_iterator begin() const { return m_map.begin(); } |
lldb_private::UniqueCStringMap<DIERef>::begin() const Line | Count | Source | 198 | 44 | const_iterator begin() const { return m_map.begin(); } |
|
199 | 51 | const_iterator end() const { return m_map.end(); } lldb_private::UniqueCStringMap<unsigned int>::end() const Line | Count | Source | 199 | 7 | const_iterator end() const { return m_map.end(); } |
lldb_private::UniqueCStringMap<DIERef>::end() const Line | Count | Source | 199 | 44 | const_iterator end() const { return m_map.end(); } |
|
200 | | |
201 | | // Range-based for loop for all entries of the specified ConstString name. |
202 | | llvm::iterator_range<const_iterator> |
203 | 162k | equal_range(ConstString unique_cstr) const { |
204 | 162k | return llvm::make_range( |
205 | 162k | std::equal_range(m_map.begin(), m_map.end(), unique_cstr, Compare())); |
206 | 162k | }; |
207 | | |
208 | | protected: |
209 | | struct Compare { |
210 | | bool operator()(const Entry &lhs, const Entry &rhs) { |
211 | | return operator()(lhs.cstring, rhs.cstring); |
212 | | } |
213 | | |
214 | 48.9M | bool operator()(const Entry &lhs, ConstString rhs) { |
215 | 48.9M | return operator()(lhs.cstring, rhs); |
216 | 48.9M | } lldb_private::UniqueCStringMap<unsigned int>::Compare::operator()(lldb_private::UniqueCStringMap<unsigned int>::Entry const&, lldb_private::ConstString) Line | Count | Source | 214 | 48.8M | bool operator()(const Entry &lhs, ConstString rhs) { | 215 | 48.8M | return operator()(lhs.cstring, rhs); | 216 | 48.8M | } |
lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Compare::operator()(lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Entry const&, lldb_private::ConstString) Line | Count | Source | 214 | 891 | bool operator()(const Entry &lhs, ConstString rhs) { | 215 | 891 | return operator()(lhs.cstring, rhs); | 216 | 891 | } |
lldb_private::UniqueCStringMap<DWARFDIE>::Compare::operator()(lldb_private::UniqueCStringMap<DWARFDIE>::Entry const&, lldb_private::ConstString) Line | Count | Source | 214 | 6 | bool operator()(const Entry &lhs, ConstString rhs) { | 215 | 6 | return operator()(lhs.cstring, rhs); | 216 | 6 | } |
lldb_private::UniqueCStringMap<DIERef>::Compare::operator()(lldb_private::UniqueCStringMap<DIERef>::Entry const&, lldb_private::ConstString) Line | Count | Source | 214 | 141k | bool operator()(const Entry &lhs, ConstString rhs) { | 215 | 141k | return operator()(lhs.cstring, rhs); | 216 | 141k | } |
|
217 | | |
218 | 18.4M | bool operator()(ConstString lhs, const Entry &rhs) { |
219 | 18.4M | return operator()(lhs, rhs.cstring); |
220 | 18.4M | } lldb_private::UniqueCStringMap<unsigned int>::Compare::operator()(lldb_private::ConstString, lldb_private::UniqueCStringMap<unsigned int>::Entry const&) Line | Count | Source | 218 | 18.3M | bool operator()(ConstString lhs, const Entry &rhs) { | 219 | 18.3M | return operator()(lhs, rhs.cstring); | 220 | 18.3M | } |
lldb_private::UniqueCStringMap<DIERef>::Compare::operator()(lldb_private::ConstString, lldb_private::UniqueCStringMap<DIERef>::Entry const&) Line | Count | Source | 218 | 71.2k | bool operator()(ConstString lhs, const Entry &rhs) { | 219 | 71.2k | return operator()(lhs, rhs.cstring); | 220 | 71.2k | } |
|
221 | | |
222 | 67.4M | bool operator()(ConstString lhs, ConstString rhs) { |
223 | 67.4M | return ThreeWay(lhs, rhs) < 0; |
224 | 67.4M | } lldb_private::UniqueCStringMap<unsigned int>::Compare::operator()(lldb_private::ConstString, lldb_private::ConstString) Line | Count | Source | 222 | 67.2M | bool operator()(ConstString lhs, ConstString rhs) { | 223 | 67.2M | return ThreeWay(lhs, rhs) < 0; | 224 | 67.2M | } |
lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Compare::operator()(lldb_private::ConstString, lldb_private::ConstString) Line | Count | Source | 222 | 891 | bool operator()(ConstString lhs, ConstString rhs) { | 223 | 891 | return ThreeWay(lhs, rhs) < 0; | 224 | 891 | } |
lldb_private::UniqueCStringMap<DWARFDIE>::Compare::operator()(lldb_private::ConstString, lldb_private::ConstString) Line | Count | Source | 222 | 6 | bool operator()(ConstString lhs, ConstString rhs) { | 223 | 6 | return ThreeWay(lhs, rhs) < 0; | 224 | 6 | } |
lldb_private::UniqueCStringMap<DIERef>::Compare::operator()(lldb_private::ConstString, lldb_private::ConstString) Line | Count | Source | 222 | 213k | bool operator()(ConstString lhs, ConstString rhs) { | 223 | 213k | return ThreeWay(lhs, rhs) < 0; | 224 | 213k | } |
|
225 | | |
226 | | // This is only for uniqueness, not lexicographical ordering, so we can |
227 | | // just compare pointers. *However*, comparing pointers from different |
228 | | // allocations is UB, so we need compare their integral values instead. |
229 | 2.33G | int ThreeWay(ConstString lhs, ConstString rhs) { |
230 | 2.33G | auto lhsint = uintptr_t(lhs.GetCString()); |
231 | 2.33G | auto rhsint = uintptr_t(rhs.GetCString()); |
232 | 2.33G | if (lhsint < rhsint) |
233 | 1.46G | return -1; |
234 | 861M | if (lhsint > rhsint) |
235 | 814M | return 1; |
236 | 47.0M | return 0; |
237 | 861M | } lldb_private::UniqueCStringMap<unsigned int>::Compare::ThreeWay(lldb_private::ConstString, lldb_private::ConstString) Line | Count | Source | 229 | 2.33G | int ThreeWay(ConstString lhs, ConstString rhs) { | 230 | 2.33G | auto lhsint = uintptr_t(lhs.GetCString()); | 231 | 2.33G | auto rhsint = uintptr_t(rhs.GetCString()); | 232 | 2.33G | if (lhsint < rhsint) | 233 | 1.46G | return -1; | 234 | 861M | if (lhsint > rhsint) | 235 | 814M | return 1; | 236 | 47.0M | return 0; | 237 | 861M | } |
lldb_private::UniqueCStringMap<lldb_private::OptionValueEnumeration::EnumeratorInfo>::Compare::ThreeWay(lldb_private::ConstString, lldb_private::ConstString) Line | Count | Source | 229 | 219k | int ThreeWay(ConstString lhs, ConstString rhs) { | 230 | 219k | auto lhsint = uintptr_t(lhs.GetCString()); | 231 | 219k | auto rhsint = uintptr_t(rhs.GetCString()); | 232 | 219k | if (lhsint < rhsint) | 233 | 77.7k | return -1; | 234 | 141k | if (lhsint > rhsint) | 235 | 141k | return 1; | 236 | 442 | return 0; | 237 | 141k | } |
lldb_private::UniqueCStringMap<DWARFDIE>::Compare::ThreeWay(lldb_private::ConstString, lldb_private::ConstString) Line | Count | Source | 229 | 6 | int ThreeWay(ConstString lhs, ConstString rhs) { | 230 | 6 | auto lhsint = uintptr_t(lhs.GetCString()); | 231 | 6 | auto rhsint = uintptr_t(rhs.GetCString()); | 232 | 6 | if (lhsint < rhsint) | 233 | 0 | return -1; | 234 | 6 | if (lhsint > rhsint) | 235 | 6 | return 1; | 236 | 0 | return 0; | 237 | 6 | } |
lldb_private::UniqueCStringMap<DIERef>::Compare::ThreeWay(lldb_private::ConstString, lldb_private::ConstString) Line | Count | Source | 229 | 376k | int ThreeWay(ConstString lhs, ConstString rhs) { | 230 | 376k | auto lhsint = uintptr_t(lhs.GetCString()); | 231 | 376k | auto rhsint = uintptr_t(rhs.GetCString()); | 232 | 376k | if (lhsint < rhsint) | 233 | 269k | return -1; | 234 | 106k | if (lhsint > rhsint) | 235 | 104k | return 1; | 236 | 2.65k | return 0; | 237 | 106k | } |
|
238 | | }; |
239 | | |
240 | | collection m_map; |
241 | | }; |
242 | | |
243 | | } // namespace lldb_private |
244 | | |
245 | | #endif // LLDB_CORE_UNIQUECSTRINGMAP_H |