[PATCH] D66788: Refactor GlobList from an ad-hoc linked list to a vector

Dmitri Gribenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 04:05:42 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL370039: Refactor GlobList from an ad-hoc linked list to a vector (authored by gribozavr, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66788?vs=217322&id=217357#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66788/new/

https://reviews.llvm.org/D66788

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


Index: clang-tools-extra/trunk/clang-tidy/GlobList.h
===================================================================
--- clang-tools-extra/trunk/clang-tidy/GlobList.h
+++ clang-tools-extra/trunk/clang-tidy/GlobList.h
@@ -12,30 +12,36 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Regex.h"
-#include <memory>
+#include <vector>
 
 namespace clang {
 namespace tidy {
 
-/// Read-only set of strings represented as a list of positive and
-/// negative globs. Positive globs add all matched strings to the set, negative
-/// globs remove them in the order of appearance in the list.
+/// Read-only set of strings represented as a list of positive and negative
+/// globs.
+///
+/// Positive globs add all matched strings to the set, negative globs remove
+/// them in the order of appearance in the list.
 class GlobList {
 public:
-  /// \p GlobList is a comma-separated list of globs (only '*'
-  /// metacharacter is supported) with optional '-' prefix to denote exclusion.
+  /// \p Globs is a comma-separated list of globs (only the '*' metacharacter is
+  /// supported) with an optional '-' prefix to denote exclusion.
+  ///
+  /// An empty \p Globs string is interpreted as one glob that matches an empty
+  /// string.
   GlobList(StringRef Globs);
 
   /// 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/trunk/clang-tidy/GlobList.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/GlobList.cpp
+++ clang-tools-extra/trunk/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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66788.217357.patch
Type: text/x-patch
Size: 2884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190827/ac7df6c3/attachment-0001.bin>


More information about the llvm-commits mailing list