Skip to content

Commit 081f01f

Browse files
committed
Switch stringToCommentKind() to use StringMap lookup
1 parent 104ad48 commit 081f01f

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

clang-tools-extra/clang-doc/Representation.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,33 @@
2020
//
2121
//===----------------------------------------------------------------------===//
2222
#include "Representation.h"
23+
#include "llvm/ADT/StringMap.h"
2324
#include "llvm/Support/Error.h"
2425
#include "llvm/Support/Path.h"
2526

2627
namespace clang {
2728
namespace doc {
2829

2930
CommentKind stringToCommentKind(llvm::StringRef KindStr) {
30-
if (KindStr == "FullComment")
31-
return CommentKind::CK_FullComment;
32-
if (KindStr == "ParagraphComment")
33-
return CommentKind::CK_ParagraphComment;
34-
if (KindStr == "TextComment")
35-
return CommentKind::CK_TextComment;
36-
if (KindStr == "InlineCommandComment")
37-
return CommentKind::CK_InlineCommandComment;
38-
if (KindStr == "HTMLStartTagComment")
39-
return CommentKind::CK_HTMLStartTagComment;
40-
if (KindStr == "HTMLEndTagComment")
41-
return CommentKind::CK_HTMLEndTagComment;
42-
if (KindStr == "BlockCommandComment")
43-
return CommentKind::CK_BlockCommandComment;
44-
if (KindStr == "ParamCommandComment")
45-
return CommentKind::CK_ParamCommandComment;
46-
if (KindStr == "TParamCommandComment")
47-
return CommentKind::CK_TParamCommandComment;
48-
if (KindStr == "VerbatimBlockComment")
49-
return CommentKind::CK_VerbatimBlockComment;
50-
if (KindStr == "VerbatimBlockLineComment")
51-
return CommentKind::CK_VerbatimBlockLineComment;
52-
if (KindStr == "VerbatimLineComment")
53-
return CommentKind::CK_VerbatimLineComment;
31+
static const llvm::StringMap<CommentKind> KindMap = {
32+
{"FullComment", CommentKind::CK_FullComment},
33+
{"ParagraphComment", CommentKind::CK_ParagraphComment},
34+
{"TextComment", CommentKind::CK_TextComment},
35+
{"InlineCommandComment", CommentKind::CK_InlineCommandComment},
36+
{"HTMLStartTagComment", CommentKind::CK_HTMLStartTagComment},
37+
{"HTMLEndTagComment", CommentKind::CK_HTMLEndTagComment},
38+
{"BlockCommandComment", CommentKind::CK_BlockCommandComment},
39+
{"ParamCommandComment", CommentKind::CK_ParamCommandComment},
40+
{"TParamCommandComment", CommentKind::CK_TParamCommandComment},
41+
{"VerbatimBlockComment", CommentKind::CK_VerbatimBlockComment},
42+
{"VerbatimBlockLineComment", CommentKind::CK_VerbatimBlockLineComment},
43+
{"VerbatimLineComment", CommentKind::CK_VerbatimLineComment},
44+
};
45+
46+
auto It = KindMap.find(KindStr);
47+
if (It != KindMap.end()) {
48+
return It->second;
49+
}
5450
return CommentKind::CK_Unknown;
5551
}
5652

0 commit comments

Comments
 (0)