-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[clang-format][NFC] Replace a function with StringRef::contains #146245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesFull diff: https://github.com/llvm/llvm-project/pull/146245.diff 1 Files Affected:
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index def0d73e77539..24912c25ef8c6 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -26,18 +26,6 @@ namespace clang {
namespace format {
static constexpr StringRef Blanks = " \t\v\f\r";
-static bool IsBlank(char C) {
- switch (C) {
- case ' ':
- case '\t':
- case '\v':
- case '\f':
- case '\r':
- return true;
- default:
- return false;
- }
-}
static StringRef getLineCommentIndentPrefix(StringRef Comment,
const FormatStyle &Style) {
@@ -193,7 +181,7 @@ getStringSplit(StringRef Text, unsigned UsedColumns, unsigned ColumnLimit,
if (Chars > MaxSplit || Text.size() <= Advance)
break;
- if (IsBlank(Text[0]))
+ if (Blanks.contains(Text[0]))
SpaceOffset = SplitPoint;
if (Text[0] == '/')
SlashOffset = SplitPoint;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it is less code, I find a bit harder to understand and the code gen is far worse: https://gcc.godbolt.org/z/KzG4YnTh3
More importantly, we wouldn't need to update |
To make it fair you have to add the It's true, that And for the readability we obviously disagree. |
Had we used
Before:
After:
Runtime aside, it's bad for maintainability to hardcode the characters in |
No description provided.