[llvm] [DWARFLinkerTypeUnit] Simplify code around try_emplace (NFC) (PR #109670)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 07:33:08 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From 9823a511e9f2d0f4cd581eb656b676404989b290 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 23 Sep 2024 07:23:52 -0700
Subject: [PATCH] [DWARFLinkerTypeUnit] Simplify code around try_emplace (NFC)
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.
---
llvm/lib/DWARFLinker/Parallel/DWARFLinkerTypeUnit.cpp | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerTypeUnit.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerTypeUnit.cpp
index 9a115ace6ce3a3..9b626239e075fb 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerTypeUnit.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerTypeUnit.cpp
@@ -286,21 +286,18 @@ uint32_t TypeUnit::addFileNameIntoLinetable(StringEntry *Dir,
DirIdx++;
}
- uint32_t FileIdx = 0;
- auto [FileEntry, Inserted] = FileNamesMap.try_emplace({FileName, DirIdx});
+ auto [FileEntry, Inserted] = FileNamesMap.try_emplace(
+ {FileName, DirIdx}, LineTable.Prologue.FileNames.size());
if (Inserted) {
// We currently do not support more than UINT32_MAX files.
assert(LineTable.Prologue.FileNames.size() < UINT32_MAX);
- FileIdx = LineTable.Prologue.FileNames.size();
- FileEntry->second = FileIdx;
LineTable.Prologue.FileNames.push_back(DWARFDebugLine::FileNameEntry());
LineTable.Prologue.FileNames.back().Name = DWARFFormValue::createFromPValue(
dwarf::DW_FORM_string, FileName->getKeyData());
LineTable.Prologue.FileNames.back().DirIdx = DirIdx;
- } else {
- FileIdx = FileEntry->second;
}
+ uint32_t FileIdx = FileEntry->second;
return getVersion() < 5 ? FileIdx + 1 : FileIdx;
}
More information about the llvm-commits
mailing list