jankratochvil updated this revision to Diff 219147.
jankratochvil added a comment.
I have tried the `MapVector` with `RegularExpressionSP` as its key as suggested
by @labath but that would be even more code than the `std::list` I provided
here, both for its custom shared-pointer sorting and for its
`EmptyKey`+`TombstoneKey` if we should not put `std::map` there.
So I returned back to a single `std::vector` as originally suggested by @labath
and after fixing missing `Delete` in the `Add` implementation for vector it I
think that may be a good compromise from all the variants.
Repository:
rLLDB LLDB
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66654/new/
https://reviews.llvm.org/D66654
Files:
lldb/include/lldb/DataFormatters/FormattersContainer.h
lldb/include/lldb/Utility/RegularExpression.h
lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py
Index: lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py
+++ lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py
@@ -136,6 +136,13 @@
self.expect("frame variable int_array",
substrs=['1,2'])
+ # Test the patterns are matched in reverse-chronological order.
+ self.runCmd(
+ 'type summary add --summary-string \"${var[2-3]}\" "int []"')
+
+ self.expect("frame variable int_array",
+ substrs=['3,4'])
+
self.runCmd("type summary clear")
self.runCmd("type summary add -c -x \"i_am_cool \[[0-9]\]\"")
Index: lldb/include/lldb/Utility/RegularExpression.h
===================================================================
--- lldb/include/lldb/Utility/RegularExpression.h
+++ lldb/include/lldb/Utility/RegularExpression.h
@@ -78,10 +78,6 @@
/// otherwise.
llvm::Error GetError() const;
- bool operator<(const RegularExpression &rhs) const {
- return GetText() < rhs.GetText();
- }
-
bool operator==(const RegularExpression &rhs) const {
return GetText() == rhs.GetText();
}
Index: lldb/include/lldb/DataFormatters/FormattersContainer.h
===================================================================
--- lldb/include/lldb/DataFormatters/FormattersContainer.h
+++ lldb/include/lldb/DataFormatters/FormattersContainer.h
@@ -65,7 +65,7 @@
template <typename KeyType, typename ValueType> class FormatMap {
public:
typedef typename ValueType::SharedPointer ValueSP;
- typedef std::map<KeyType, ValueSP> MapType;
+ typedef std::vector<std::pair<KeyType, ValueSP>> MapType;
typedef typename MapType::iterator MapIterator;
typedef std::function<bool(const KeyType &, const ValueSP &)> ForEachCallback;
@@ -79,20 +79,22 @@
entry->GetRevision() = 0;
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
- m_map[std::move(name)] = entry;
+ Delete(name);
+ m_map.push_back(std::make_pair(std::move(name), std::move(entry)));
if (listener)
listener->Changed();
}
bool Delete(const KeyType &name) {
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
- MapIterator iter = m_map.find(name);
- if (iter == m_map.end())
- return false;
- m_map.erase(iter);
- if (listener)
- listener->Changed();
- return true;
+ for (MapIterator iter = m_map.begin(); iter != m_map.end(); ++iter)
+ if (iter->first == name) {
+ m_map.erase(iter);
+ if (listener)
+ listener->Changed();
+ return true;
+ }
+ return false;
}
void Clear() {
@@ -104,11 +106,12 @@
bool Get(const KeyType &name, ValueSP &entry) {
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
- MapIterator iter = m_map.find(name);
- if (iter == m_map.end())
- return false;
- entry = iter->second;
- return true;
+ for (MapIterator iter = m_map.begin(); iter != m_map.end(); ++iter)
+ if (iter->first == name) {
+ entry = iter->second;
+ return true;
+ }
+ return false;
}
void ForEach(ForEachCallback callback) {
@@ -127,29 +130,17 @@
ValueSP GetValueAtIndex(size_t index) {
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
- MapIterator iter = m_map.begin();
- MapIterator end = m_map.end();
- while (index > 0) {
- iter++;
- index--;
- if (end == iter)
- return ValueSP();
- }
- return iter->second;
+ if (index >= m_map.size())
+ return ValueSP();
+ return m_map[index].second;
}
// If caller holds the mutex we could return a reference without copy ctor.
KeyType GetKeyAtIndex(size_t index) {
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
- MapIterator iter = m_map.begin();
- MapIterator end = m_map.end();
- while (index > 0) {
- iter++;
- index--;
- if (end == iter)
- return KeyType();
- }
- return iter->first;
+ if (index >= m_map.size())
+ return {};
+ return m_map[index].first;
}
protected:
@@ -172,8 +163,9 @@
public:
typedef typename BackEndType::MapType MapType;
typedef typename MapType::iterator MapIterator;
- typedef typename MapType::key_type MapKeyType;
- typedef typename MapType::mapped_type MapValueType;
+ typedef typename MapType::reverse_iterator MapReverseIterator;
+ typedef KeyType MapKeyType;
+ typedef std::shared_ptr<ValueType> MapValueType;
typedef typename BackEndType::ForEachCallback ForEachCallback;
typedef typename std::shared_ptr<FormattersContainer<KeyType, ValueType>>
SharedPointer;
@@ -295,8 +287,9 @@
RegularExpression *dummy) {
llvm::StringRef key_str = key.GetStringRef();
std::lock_guard<std::recursive_mutex> guard(m_format_map.mutex());
- MapIterator pos, end = m_format_map.map().end();
- for (pos = m_format_map.map().begin(); pos != end; pos++) {
+ // Patterns are matched in reverse-chronological order.
+ MapReverseIterator pos, end = m_format_map.map().rend();
+ for (pos = m_format_map.map().rbegin(); pos != end; pos++) {
const RegularExpression ®ex = pos->first;
if (regex.Execute(key_str)) {
value = pos->second;
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits