This is an archive of the discontinued LLVM Phabricator instance.

[symbolizer][NFC] Move file argument parsing into separate function
ClosedPublic

Authored by sepavloff on Aug 3 2023, 2:40 AM.

Details

Summary

The code that gets binary file name is moved to a separate function.
It makes the code of parseCommand cleaner and allows to reuse the
parsing code.

Diff Detail

Event Timeline

sepavloff created this revision.Aug 3 2023, 2:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 2:40 AM
sepavloff requested review of this revision.Aug 3 2023, 2:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 2:40 AM
ikudrin added inline comments.Aug 3 2023, 9:27 PM
llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
130

The function returns a part of its input, so there is no need to allocate new memory for that, StringRef is enough. It should be the responsibility of the caller to copy the result if necessary.

Also, the function can update Source if it is passed as a reference, which would simplify the code even more.

155–156

It looks like kDelimiters can be removed.

sepavloff updated this revision to Diff 547166.Aug 4 2023, 4:50 AM

Address reviewer's notes

sepavloff added inline comments.Aug 4 2023, 4:55 AM
llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
130

Indeed, StringRef can be used here.

the function can update Source if it is passed as a reference

Passing by reference can bring new issues. In this case it prevents from using constructs like getSpaceDelimitedWord(Source.ltrim()).

155–156

It is true. Removed.

ikudrin added inline comments.Aug 4 2023, 4:38 PM
llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
130

Are there any reasons not to do the trimming within this function?

sepavloff updated this revision to Diff 547491.Aug 5 2023, 8:43 AM

Pass Source by reference in getSpaceDelimitedWord

ikudrin accepted this revision.Aug 8 2023, 5:54 PM

LGTM

This revision is now accepted and ready to land.Aug 8 2023, 5:54 PM
MaskRay accepted this revision.Aug 8 2023, 7:13 PM
jhenderson accepted this revision.Aug 8 2023, 11:40 PM

One nit from me, otherwise LGTM too.

llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
137

Nit: https://llvm.org/docs/CodingStandards.html#prefer-preincrement

(I know this was there before, but since you're moving the code, you might as well fix it at the same time)

This revision was landed with ongoing or failed builds.Aug 8 2023, 11:59 PM
This revision was automatically updated to reflect the committed changes.