Skip to content

Commit bfbdab6

Browse files
committed
[Debuginfo] Remove redundand variable from getAttributeValue()
Summary: AttrIndex could be removed from DWARFAbbreviationDeclaration::getAttributeValue. Reviewers: clayborg, dblaikie Differential Revision: https://reviews.llvm.org/D78672
1 parent 0ddb203 commit bfbdab6

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ DWARFAbbreviationDeclaration::findAttributeIndex(dwarf::Attribute Attr) const {
150150
Optional<DWARFFormValue> DWARFAbbreviationDeclaration::getAttributeValue(
151151
const uint64_t DIEOffset, const dwarf::Attribute Attr,
152152
const DWARFUnit &U) const {
153+
// Check if this abbreviation has this attribute without needing to skip
154+
// any data so we can return quickly if it doesn't.
153155
Optional<uint32_t> MatchAttrIndex = findAttributeIndex(Attr);
154156
if (!MatchAttrIndex)
155157
return None;
@@ -159,26 +161,24 @@ Optional<DWARFFormValue> DWARFAbbreviationDeclaration::getAttributeValue(
159161
// Add the byte size of ULEB that for the abbrev Code so we can start
160162
// skipping the attribute data.
161163
uint64_t Offset = DIEOffset + CodeByteSize;
162-
uint32_t AttrIndex = 0;
163-
for (const auto &Spec : AttributeSpecs) {
164-
if (*MatchAttrIndex == AttrIndex) {
165-
// We have arrived at the attribute to extract, extract if from Offset.
166-
if (Spec.isImplicitConst())
167-
return DWARFFormValue::createFromSValue(Spec.Form,
168-
Spec.getImplicitConstValue());
169-
170-
DWARFFormValue FormValue(Spec.Form);
171-
if (FormValue.extractValue(DebugInfoData, &Offset, U.getFormParams(), &U))
172-
return FormValue;
173-
}
174-
// March Offset along until we get to the attribute we want.
175-
if (auto FixedSize = Spec.getByteSize(U))
164+
for (uint32_t CurAttrIdx = 0; CurAttrIdx != *MatchAttrIndex; ++CurAttrIdx)
165+
// Match Offset along until we get to the attribute we want.
166+
if (auto FixedSize = AttributeSpecs[CurAttrIdx].getByteSize(U))
176167
Offset += *FixedSize;
177168
else
178-
DWARFFormValue::skipValue(Spec.Form, DebugInfoData, &Offset,
179-
U.getFormParams());
180-
++AttrIndex;
181-
}
169+
DWARFFormValue::skipValue(AttributeSpecs[CurAttrIdx].Form, DebugInfoData,
170+
&Offset, U.getFormParams());
171+
172+
// We have arrived at the attribute to extract, extract if from Offset.
173+
const AttributeSpec &Spec = AttributeSpecs[*MatchAttrIndex];
174+
if (Spec.isImplicitConst())
175+
return DWARFFormValue::createFromSValue(Spec.Form,
176+
Spec.getImplicitConstValue());
177+
178+
DWARFFormValue FormValue(Spec.Form);
179+
if (FormValue.extractValue(DebugInfoData, &Offset, U.getFormParams(), &U))
180+
return FormValue;
181+
182182
return None;
183183
}
184184

0 commit comments

Comments
 (0)