Skip to content

Commit 62200c1

Browse files
committed
[Markup] Fix warning in measureIndentation
The primary goal is to fix this warning: $PROJECT_PATH/swift-project/swift/lib/Markup/LineList.cpp:46:10: warning: variable 'Col' set but not used [-Wunused-but-set-variable] size_t Col = 0; I also rewrote the implementation to use StringRef functionality instead of manually walking over the characters.
1 parent b2456b1 commit 62200c1

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

lib/Markup/LineList.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,11 @@ std::string LineList::str() const {
4343
}
4444

4545
size_t swift::markup::measureIndentation(StringRef Text) {
46-
size_t Col = 0;
47-
for (size_t i = 0, e = Text.size(); i != e; ++i) {
48-
if (Text[i] == ' ' || Text[i] == '\v' || Text[i] == '\f') {
49-
++Col;
50-
continue;
51-
}
52-
53-
if (Text[i] == '\t') {
54-
Col += ((i + 8) / 8) * 8;
55-
continue;
56-
}
57-
return i;
58-
}
59-
return Text.size();
46+
static constexpr llvm::StringLiteral IndentChars(" \v\f\t");
47+
size_t FirstNonIndentPos = Text.find_first_not_of(IndentChars);
48+
if (FirstNonIndentPos == StringRef::npos)
49+
return Text.size();
50+
return FirstNonIndentPos;
6051
}
6152

6253
void LineListBuilder::addLine(llvm::StringRef Text, swift::SourceRange Range) {

0 commit comments

Comments
 (0)