bulbazord updated this revision to Diff 521771.
bulbazord added a comment.

- Use emplace_back
- llvm::SmallVector size 8 -> 4


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150418/new/

https://reviews.llvm.org/D150418

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
@@ -31,10 +31,6 @@
     form = m_form;
     val = m_value;
   }
-  typedef std::vector<DWARFAttribute> collection;
-  typedef collection::iterator iterator;
-  typedef collection::const_iterator const_iterator;
-
 protected:
   dw_attr_t m_attr;
   dw_form_t m_form;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
@@ -16,6 +16,29 @@
 
 class DWARFAbbreviationDeclaration {
 public:
+  struct AttributeSpec {
+    AttributeSpec(dw_attr_t attr, dw_form_t form, int64_t value)
+        : m_attr(attr), m_form(form), m_value(value) {}
+
+    AttributeSpec(dw_attr_t attr, dw_form_t form)
+        : m_attr(attr), m_form(form), m_value(0) {}
+
+    bool IsImplicitConst() const {
+      return m_form == lldb_private::dwarf::DW_FORM_implicit_const;
+    }
+
+    int64_t GetImplicitConstValue() const { return m_value; }
+
+    dw_attr_t GetAttribute() const { return m_attr; }
+
+    dw_form_t GetForm() const { return m_form; }
+
+  private:
+    dw_attr_t m_attr;
+    dw_form_t m_form;
+    int64_t m_value;
+  };
+
   enum { InvalidCode = 0 };
   DWARFAbbreviationDeclaration();
 
@@ -28,17 +51,21 @@
   bool HasChildren() const { return m_has_children; }
   size_t NumAttributes() const { return m_attributes.size(); }
   dw_form_t GetFormByIndex(uint32_t idx) const {
-    return m_attributes.size() > idx ? m_attributes[idx].get_form()
+    return m_attributes.size() > idx ? m_attributes[idx].GetForm()
                                      : dw_form_t(0);
   }
 
   // idx is assumed to be valid when calling GetAttrAndFormByIndex()
   void GetAttrAndFormValueByIndex(uint32_t idx, dw_attr_t &attr,
                                   DWARFFormValue &form_value) const {
-    m_attributes[idx].get(attr, form_value.FormRef(), form_value.ValueRef());
+    const AttributeSpec &spec = m_attributes[idx];
+    attr = spec.GetAttribute();
+    form_value.FormRef() = spec.GetForm();
+    if (spec.IsImplicitConst())
+      form_value.SetSigned(spec.GetImplicitConstValue());
   }
   dw_form_t GetFormByIndexUnchecked(uint32_t idx) const {
-    return m_attributes[idx].get_form();
+    return m_attributes[idx].GetForm();
   }
   uint32_t FindAttributeIndex(dw_attr_t attr) const;
 
@@ -59,7 +86,7 @@
   uint32_t m_code = InvalidCode;
   dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
   uint8_t m_has_children = 0;
-  DWARFAttribute::collection m_attributes;
+  llvm::SmallVector<AttributeSpec, 4> m_attributes;
 };
 
 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -53,12 +53,13 @@
       return llvm::make_error<llvm::object::GenericBinaryError>(
           "malformed abbreviation declaration attribute");
 
-    DWARFFormValue::ValueType val;
+    if (form == DW_FORM_implicit_const) {
+      int64_t value = data.GetSLEB128(offset_ptr);
+      m_attributes.emplace_back(attr, form, value);
+      continue;
+    }
 
-    if (form == DW_FORM_implicit_const)
-      val.value.sval = data.GetSLEB128(offset_ptr);
-
-    m_attributes.push_back(DWARFAttribute(attr, form, val));
+    m_attributes.emplace_back(attr, form);
   }
 
   return llvm::make_error<llvm::object::GenericBinaryError>(
@@ -72,10 +73,8 @@
 
 uint32_t
 DWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const {
-  uint32_t i;
-  const uint32_t kNumAttributes = m_attributes.size();
-  for (i = 0; i < kNumAttributes; ++i) {
-    if (m_attributes[i].get_attr() == attr)
+  for (size_t i = 0; i < m_attributes.size(); ++i) {
+    if (m_attributes[i].GetAttribute() == attr)
       return i;
   }
   return DW_INVALID_INDEX;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to