This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] NFC: Switch to range-based for loops in OptParserEmitter
ClosedPublic

Authored by jansvoboda11 on Dec 18 2020, 1:53 AM.

Details

Summary

This simplifies the code a bit. No functionality change.

Diff Detail

Event Timeline

jansvoboda11 requested review of this revision.Dec 18 2020, 1:53 AM
jansvoboda11 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 18 2020, 1:54 AM
dexonsmith accepted this revision.Dec 18 2020, 1:28 PM

Thanks for the cleanup! I have a few nits below, some of which will help to reduce the diff. LGTM once you fix those.

llvm/utils/TableGen/OptParserEmitter.cpp
237
  • This name is confusing to me because PrefixIt doesn't seem to be an iterator (but It suggests it is). Can this be Prefix instead? Or maybe P?
  • Should this be const auto & to avoid the copy? If not, please spell out the type so it's easy to confirm at the call site that a copy is cheap enough.
244–246
  • You might consider dropping the braces since you're touching this code anyway.
  • I think the type here could be a by-value StringRef to avoid having to change it if the string storage implementation changes in the future.
255

You can reduce the diff with:

for (const Record &R : llvm::make_pointee_range(Groups)) {

A side benefit is we keep a non-non-null variable from looking like it could be null to the casual reader of later lines.

340–341

StringRef is cheap to copy; just use it by-value. Generally we try to avoid taking it by-reference (unless it's being modified, or if it somehow avoids an #include although it's so pervasive that's probably not worth doing).

391

As above, you can use make_pointee_range.

458

make_pointee_range

This revision is now accepted and ready to land.Dec 18 2020, 1:28 PM

Thanks for the suggestions! llvm::make_pointee_range is handy.

Incorporate review feedback

This revision was landed with ongoing or failed builds.Dec 21 2020, 3:37 AM
This revision was automatically updated to reflect the committed changes.