DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich, lebedev.ri.
DiegoAstiazaran added a project: clang-tools-extra.

De-duplicate comments in reduce function.
When two files include the same header file, this file's content is mapped 
twice and comments are duplicated after the reduce stage.


https://reviews.llvm.org/D62970

Files:
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h


Index: clang-tools-extra/clang-doc/Representation.h
===================================================================
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -47,6 +47,23 @@
   CommentInfo(CommentInfo &Other) = delete;
   CommentInfo(CommentInfo &&Other) = default;
 
+  bool operator==(const CommentInfo &Other) const {
+    bool AreEqual =
+        Kind == Other.Kind && Text == Other.Text && Name == Other.Name &&
+        Direction == Other.Direction && ParamName == Other.ParamName &&
+        CloseName == Other.CloseName && SelfClosing == Other.SelfClosing &&
+        Explicit == Other.Explicit && AttrKeys == Other.AttrKeys &&
+        AttrValues == Other.AttrValues && Args == Other.Args &&
+        Children.size() == Other.Children.size();
+    if (!AreEqual)
+      return false;
+    for (unsigned I = 0; I < Children.size(); ++I) {
+      if (!(*Children[I] == *Other.Children[I]))
+        return false;
+    }
+    return true;
+  }
+
   SmallString<16>
       Kind; // Kind of comment (FullComment, ParagraphComment, TextComment,
             // InlineCommandComment, HTMLStartTagComment, HTMLEndTagComment,
Index: clang-tools-extra/clang-doc/Representation.cpp
===================================================================
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -120,8 +120,12 @@
   if (Namespace.empty())
     Namespace = std::move(Other.Namespace);
   // Unconditionally extend the description, since each decl may have a 
comment.
-  std::move(Other.Description.begin(), Other.Description.end(),
-            std::back_inserter(Description));
+  for (auto &Comment : Other.Description) {
+    bool IsCommentUnique = std::find(Description.begin(), Description.end(),
+                                     Comment) == Description.end();
+    if (IsCommentUnique)
+      Description.emplace_back(std::move(Comment));
+  }
 }
 
 bool Info::mergeable(const Info &Other) {


Index: clang-tools-extra/clang-doc/Representation.h
===================================================================
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -47,6 +47,23 @@
   CommentInfo(CommentInfo &Other) = delete;
   CommentInfo(CommentInfo &&Other) = default;
 
+  bool operator==(const CommentInfo &Other) const {
+    bool AreEqual =
+        Kind == Other.Kind && Text == Other.Text && Name == Other.Name &&
+        Direction == Other.Direction && ParamName == Other.ParamName &&
+        CloseName == Other.CloseName && SelfClosing == Other.SelfClosing &&
+        Explicit == Other.Explicit && AttrKeys == Other.AttrKeys &&
+        AttrValues == Other.AttrValues && Args == Other.Args &&
+        Children.size() == Other.Children.size();
+    if (!AreEqual)
+      return false;
+    for (unsigned I = 0; I < Children.size(); ++I) {
+      if (!(*Children[I] == *Other.Children[I]))
+        return false;
+    }
+    return true;
+  }
+
   SmallString<16>
       Kind; // Kind of comment (FullComment, ParagraphComment, TextComment,
             // InlineCommandComment, HTMLStartTagComment, HTMLEndTagComment,
Index: clang-tools-extra/clang-doc/Representation.cpp
===================================================================
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -120,8 +120,12 @@
   if (Namespace.empty())
     Namespace = std::move(Other.Namespace);
   // Unconditionally extend the description, since each decl may have a comment.
-  std::move(Other.Description.begin(), Other.Description.end(),
-            std::back_inserter(Description));
+  for (auto &Comment : Other.Description) {
+    bool IsCommentUnique = std::find(Description.begin(), Description.end(),
+                                     Comment) == Description.end();
+    if (IsCommentUnique)
+      Description.emplace_back(std::move(Comment));
+  }
 }
 
 bool Info::mergeable(const Info &Other) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to