summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/NamespaceEndCommentsFixer.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2018-03-20 20:43:12 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2018-03-20 20:43:12 +0000
commit8ef820a6ede43802172161d2477c2cf9cd066790 (patch)
treef83cf5594c32de23db7a2e615f6261ffa8c896b5 /clang/lib/Format/NamespaceEndCommentsFixer.cpp
parent0d40f125967df7971eaff0a23cc78372edd4a904 (diff)
downloadbcm5719-llvm-8ef820a6ede43802172161d2477c2cf9cd066790.tar.gz
bcm5719-llvm-8ef820a6ede43802172161d2477c2cf9cd066790.zip
[format] Initialize regex lazily
No need to pay for this on program startup, and also no need to destroy it on process end. llvm-svn: 328041
Diffstat (limited to 'clang/lib/Format/NamespaceEndCommentsFixer.cpp')
-rw-r--r--clang/lib/Format/NamespaceEndCommentsFixer.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/clang/lib/Format/NamespaceEndCommentsFixer.cpp b/clang/lib/Format/NamespaceEndCommentsFixer.cpp
index df99bb2e138..ee11959af3a 100644
--- a/clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ b/clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -27,13 +27,6 @@ namespace {
// Short namespaces don't need an end comment.
static const int kShortNamespaceMaxLines = 1;
-// Matches a valid namespace end comment.
-// Valid namespace end comments don't need to be edited.
-static llvm::Regex kNamespaceCommentPattern =
- llvm::Regex("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
- "namespace( +([a-zA-Z0-9:_]+))?\\.? *(\\*/)?$",
- llvm::Regex::IgnoreCase);
-
// Computes the name of a namespace given the namespace token.
// Returns "" for anonymous namespace.
std::string computeName(const FormatToken *NamespaceTok) {
@@ -67,8 +60,15 @@ bool hasEndComment(const FormatToken *RBraceTok) {
bool validEndComment(const FormatToken *RBraceTok, StringRef NamespaceName) {
assert(hasEndComment(RBraceTok));
const FormatToken *Comment = RBraceTok->Next;
+
+ // Matches a valid namespace end comment.
+ // Valid namespace end comments don't need to be edited.
+ static llvm::Regex *const NamespaceCommentPattern =
+ new llvm::Regex("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
+ "namespace( +([a-zA-Z0-9:_]+))?\\.? *(\\*/)?$",
+ llvm::Regex::IgnoreCase);
SmallVector<StringRef, 7> Groups;
- if (kNamespaceCommentPattern.match(Comment->TokenText, &Groups)) {
+ if (NamespaceCommentPattern->match(Comment->TokenText, &Groups)) {
StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5] : "";
// Anonymous namespace comments must not mention a namespace name.
if (NamespaceName.empty() && !NamespaceNameInComment.empty())
OpenPOWER on IntegriCloud