- added a helper function isSymbolDefined().
- Split out sorting code
- refactor symbol comparing function
Details
- Reviewers
jhenderson MaskRay hubert.reinterpretcast Esme - Group Reviewers
Restricted Project - Commits
- rGd11915b5c73e: [NFC] Refactor llvm-nm symbol comparing and split sorting
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
Mostly looks good
llvm/tools/llvm-nm/llvm-nm.cpp | ||
---|---|---|
226–231 | ||
230 | https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code Re-align the next line. | |
249 | Is operator> used? If used, can the use site be refactored to only use operator<? |
llvm/tools/llvm-nm/llvm-nm.cpp | ||
---|---|---|
226–231 | thanks | |
230 | thanks | |
249 | yes, the operator> is used to change llvm::sort(SymbolList, [=](const NMSymbol &A, const NMSymbol &B) -> bool { return Cmp(B, A); }); ---->
there is Jame's comment as |
Mostly looks fine to me.
Change the title/commit summary to "[NFC] Refactor llvm-nm symbol sorting" (will need the additional patch mentioned inline).
llvm/tools/llvm-nm/llvm-nm.cpp | ||
---|---|---|
234–235 | Since the NMSymbol class has no private members, do you need the friend operator declarations? | |
249 | Just noting that if @MaskRay prefers using the lambda and avoid the operator>, I'm okay with that. | |
658–660 | I'm okay with this switch to stable_sort, but if I'm not mistaken, this means that under some cases, it might be a subtle behaviour change (in a good way) that could result in people seeing "identical" symbols in different orders before and after this patch. To keep this patch as a pure refactor, I suggest you create a separate patch that handles this behaviour change, by simply swapping sort to stable_sort. Then, you can add the [NFC] tag to this patch. |
llvm/tools/llvm-nm/llvm-nm.cpp | ||
---|---|---|
234–235 | thanks , good catch. |
Change the title/commit summary to "[NFC] Refactor llvm-nm symbol sorting" (will need the additional patch mentioned inline).
Patch title still doesn't match the suggested correction.
I do not think we need to additional patch for it. using std::sort is OK for export symbol list, " export symbol list" do not need to change std::stable_sort (if the two symbol is equal at symbol name and visibility, and we will remove the duplication symbol finally). and for other functionality, the code is already using the std::sort , do we need to change it?
llvm/tools/llvm-nm/llvm-nm.cpp | ||
---|---|---|
249 | Actually, I think it'd be better to do: llvm::sort(Symbols); if (ReverseSort) std::reverse(Symbols.begin(), Symbols.end()); NMSymbol is not trivially copyable, so llvm::sort expands to std::sort. |
https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
Re-align the next line.