Skip to content

Commit 2028687

Browse files
[DWARFLinkerTypeUnit] Simplify code around try_emplace (NFC) (#109670)
Without this patch, we first default-construct a value with try_emplace and then immediately override it with a new value. This patch inserts the final value with try_emplace and simplies the code around it.
1 parent 86c6403 commit 2028687

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

llvm/lib/DWARFLinker/Parallel/DWARFLinkerTypeUnit.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,18 @@ uint32_t TypeUnit::addFileNameIntoLinetable(StringEntry *Dir,
286286
DirIdx++;
287287
}
288288

289-
uint32_t FileIdx = 0;
290-
auto [FileEntry, Inserted] = FileNamesMap.try_emplace({FileName, DirIdx});
289+
auto [FileEntry, Inserted] = FileNamesMap.try_emplace(
290+
{FileName, DirIdx}, LineTable.Prologue.FileNames.size());
291291
if (Inserted) {
292292
// We currently do not support more than UINT32_MAX files.
293293
assert(LineTable.Prologue.FileNames.size() < UINT32_MAX);
294-
FileIdx = LineTable.Prologue.FileNames.size();
295-
FileEntry->second = FileIdx;
296294
LineTable.Prologue.FileNames.push_back(DWARFDebugLine::FileNameEntry());
297295
LineTable.Prologue.FileNames.back().Name = DWARFFormValue::createFromPValue(
298296
dwarf::DW_FORM_string, FileName->getKeyData());
299297
LineTable.Prologue.FileNames.back().DirIdx = DirIdx;
300-
} else {
301-
FileIdx = FileEntry->second;
302298
}
303299

300+
uint32_t FileIdx = FileEntry->second;
304301
return getVersion() < 5 ? FileIdx + 1 : FileIdx;
305302
}
306303

0 commit comments

Comments
 (0)