This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFC] Remove code duplication in InitOSO
ClosedPublic

Authored by fdeazeve on Jul 5 2023, 5:47 AM.

Details

Reviewers
JDevlieghere
Group Reviewers
Restricted Project
Commits
rG7cea22c0be95: [lldb][NFC] Remove code duplication in InitOSO
Summary

Two identical loops were iterating over different ranges, leading to code
duplication. We replace this by a loop over the concatenation of the ranges.

We also use early returns to avoid deeply nested code.

Diff Detail

Event Timeline

fdeazeve created this revision.Jul 5 2023, 5:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2023, 5:47 AM
fdeazeve requested review of this revision.Jul 5 2023, 5:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2023, 5:47 AM
fdeazeve added a reviewer: Restricted Project.Jul 5 2023, 5:48 AM

I'm a big fan of refactoring deeply-nested code to be flatter, so I'm happy to see this work being done! I wasn't aware of llvm::concat before, I probably would have used a lambda or something to do this, so it was interesting learning about that. 😄

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
347–348

Besides the typo, is this comment correct? We're not verifying the claim in the comment AFAICT.

JDevlieghere accepted this revision.Jul 5 2023, 9:13 AM

I'm a big fan of refactoring deeply-nested code to be flatter, so I'm happy to see this work being done! I wasn't aware of llvm::concat before, I probably would have used a lambda or something to do this, so it was interesting learning about that. 😄

+1 on both accounts. LGTM modulo the comment.

This revision is now accepted and ready to land.Jul 5 2023, 9:13 AM
fdeazeve added inline comments.Jul 5 2023, 10:23 AM
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
347–348

I think this is one of those situations where "if this is not true, the linker did not do its job".
That said, we should not crash, so I will change the condition to: sibling_idx <= i || sibling_idx == UINT32_MAX

fdeazeve updated this revision to Diff 537524.Jul 5 2023, 3:23 PM

Address review comment

This revision was automatically updated to reflect the committed changes.