gribozavr created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I think it makes method implementations more obvious.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66788

Files:
  clang-tools-extra/clang-tidy/GlobList.cpp
  clang-tools-extra/clang-tidy/GlobList.h


Index: clang-tools-extra/clang-tidy/GlobList.h
===================================================================
--- clang-tools-extra/clang-tidy/GlobList.h
+++ clang-tools-extra/clang-tidy/GlobList.h
@@ -12,7 +12,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Regex.h"
-#include <memory>
+#include <vector>
 
 namespace clang {
 namespace tidy {
@@ -28,14 +28,15 @@
 
   /// Returns \c true if the pattern matches \p S. The result is the last
   /// matching glob's Positive flag.
-  bool contains(StringRef S) { return contains(S, false); }
+  bool contains(StringRef S);
 
 private:
-  bool contains(StringRef S, bool Contains);
 
-  bool Positive;
-  llvm::Regex Regex;
-  std::unique_ptr<GlobList> NextGlob;
+  struct GlobListItem {
+    bool IsPositive;
+    mutable llvm::Regex Regex;
+  };
+  std::vector<GlobListItem> Items;
 };
 
 } // end namespace tidy
Index: clang-tools-extra/clang-tidy/GlobList.cpp
===================================================================
--- clang-tools-extra/clang-tidy/GlobList.cpp
+++ clang-tools-extra/clang-tidy/GlobList.cpp
@@ -42,15 +42,20 @@
   return llvm::Regex(RegexText);
 }
 
-GlobList::GlobList(StringRef Globs)
-    : Positive(!ConsumeNegativeIndicator(Globs)), Regex(ConsumeGlob(Globs)),
-      NextGlob(Globs.empty() ? nullptr : new GlobList(Globs)) {}
-
-bool GlobList::contains(StringRef S, bool Contains) {
-  if (Regex.match(S))
-    Contains = Positive;
+GlobList::GlobList(StringRef Globs) {
+  do {
+    GlobListItem Item;
+    Item.IsPositive = !ConsumeNegativeIndicator(Globs);
+    Item.Regex = ConsumeGlob(Globs);
+    Items.push_back(std::move(Item));
+  } while (!Globs.empty());
+}
 
-  if (NextGlob)
-    Contains = NextGlob->contains(S, Contains);
+bool GlobList::contains(StringRef S) {
+  bool Contains = false;
+  for (const GlobListItem &Item : Items) {
+    if (Item.Regex.match(S))
+      Contains = Item.IsPositive;
+  }
   return Contains;
 }


Index: clang-tools-extra/clang-tidy/GlobList.h
===================================================================
--- clang-tools-extra/clang-tidy/GlobList.h
+++ clang-tools-extra/clang-tidy/GlobList.h
@@ -12,7 +12,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Regex.h"
-#include <memory>
+#include <vector>
 
 namespace clang {
 namespace tidy {
@@ -28,14 +28,15 @@
 
   /// Returns \c true if the pattern matches \p S. The result is the last
   /// matching glob's Positive flag.
-  bool contains(StringRef S) { return contains(S, false); }
+  bool contains(StringRef S);
 
 private:
-  bool contains(StringRef S, bool Contains);
 
-  bool Positive;
-  llvm::Regex Regex;
-  std::unique_ptr<GlobList> NextGlob;
+  struct GlobListItem {
+    bool IsPositive;
+    mutable llvm::Regex Regex;
+  };
+  std::vector<GlobListItem> Items;
 };
 
 } // end namespace tidy
Index: clang-tools-extra/clang-tidy/GlobList.cpp
===================================================================
--- clang-tools-extra/clang-tidy/GlobList.cpp
+++ clang-tools-extra/clang-tidy/GlobList.cpp
@@ -42,15 +42,20 @@
   return llvm::Regex(RegexText);
 }
 
-GlobList::GlobList(StringRef Globs)
-    : Positive(!ConsumeNegativeIndicator(Globs)), Regex(ConsumeGlob(Globs)),
-      NextGlob(Globs.empty() ? nullptr : new GlobList(Globs)) {}
-
-bool GlobList::contains(StringRef S, bool Contains) {
-  if (Regex.match(S))
-    Contains = Positive;
+GlobList::GlobList(StringRef Globs) {
+  do {
+    GlobListItem Item;
+    Item.IsPositive = !ConsumeNegativeIndicator(Globs);
+    Item.Regex = ConsumeGlob(Globs);
+    Items.push_back(std::move(Item));
+  } while (!Globs.empty());
+}
 
-  if (NextGlob)
-    Contains = NextGlob->contains(S, Contains);
+bool GlobList::contains(StringRef S) {
+  bool Contains = false;
+  for (const GlobListItem &Item : Items) {
+    if (Item.Regex.match(S))
+      Contains = Item.IsPositive;
+  }
   return Contains;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to