This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] [NFC] Restructure getLineCommentIndentPrefix
ClosedPublic

Authored by HazardyKnusperkeks on Jan 20 2021, 12:52 PM.

Details

Summary

When sorting the known prefixes after length the if in the loop will hit at most once, so we can return from there.

Also replace the inner loop with an algorithm, that makes it more readable.

Diff Detail

Event Timeline

HazardyKnusperkeks requested review of this revision.Jan 20 2021, 12:52 PM
HazardyKnusperkeks created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2021, 12:52 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
curdeius added inline comments.Jan 20 2021, 2:36 PM
clang/lib/Format/BreakableToken.cpp
44

I'd rather put asserts instead of this comment.

Now with assert.

We could do a static_assert, but then we would have to write our own is_sorted, since the std is only constexpr in C++20.

Empty lines removed.

curdeius accepted this revision.Jan 21 2021, 2:28 PM

Just an assert is ok IMO. We may fix it when LLVM will be compiled with C++20 but this code may change before it happens.

This revision is now accepted and ready to land.Jan 21 2021, 2:28 PM