This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy][NFC] Tweak GlobList to iterate backwards
ClosedPublic

Authored by njames93 on Nov 8 2020, 8:18 AM.

Details

Summary

By iterating backwards over the globs we can exit the loop as soon as we find a match.

While we're here:

  • Regex doesn't need to be mutable.
  • We can reserve the amount of Globs needed ahead of time.
  • Using a SmallVector with size 0 is slightly more space efficient than a std::vector.

Diff Detail

Event Timeline

njames93 created this revision.Nov 8 2020, 8:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2020, 8:18 AM
njames93 requested review of this revision.Nov 8 2020, 8:18 AM
njames93 retitled this revision from GNU nano 4.8 /tmp/edit.7czvmlx7um4go4c0/commit-message Modified [clang-tidy][NFC] Tweak GlobList to iterate backwards to [clang-tidy][NFC] Tweak GlobList to iterate backwards.Nov 8 2020, 8:19 AM
aaron.ballman accepted this revision.Nov 10 2020, 5:54 AM

LGTM with a request to add a comment.

clang-tools-extra/clang-tidy/GlobList.cpp
56–58

I'd appreciate a comment here that mentions *why* reversing backwards means we can early return. It took me a few tries to remember that glob patterns can undo earlier glob patterns, so that the last pattern is the one that matters.

This revision is now accepted and ready to land.Nov 10 2020, 5:54 AM
njames93 added inline comments.Nov 10 2020, 6:10 AM
clang-tools-extra/clang-tidy/GlobList.cpp
56–58

It does list that fact in the documentation for the function, but I'll put it in here too.

aaron.ballman added inline comments.Nov 10 2020, 6:11 AM
clang-tools-extra/clang-tidy/GlobList.cpp
56–58

Oh, I missed that from the header -- nevermind, it's your call if you want to add the comment or not. :-)

This revision was automatically updated to reflect the committed changes.