[Cmake-commits] CMake branch, master, updated. v3.11.2-859-gfdb9d1b

Kitware Robot kwrobot at kitware.com
Wed May 30 10:05:06 EDT 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, master has been updated
       via  fdb9d1ba042fb517da0bf03a3781dd7a3b506f69 (commit)
       via  6d7c0740556fb06689c4d332fac685d70d83b1fe (commit)
       via  281f59536f8c16f9eacf175f8316a82f09629203 (commit)
      from  e21245ecafae78ff2fd3947f95cc30eac68ed5e8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fdb9d1ba042fb517da0bf03a3781dd7a3b506f69
commit fdb9d1ba042fb517da0bf03a3781dd7a3b506f69
Merge: e21245e 6d7c074
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Wed May 30 13:55:49 2018 +0000
Commit:     Kitware Robot <kwrobot at kitware.com>
CommitDate: Wed May 30 09:56:00 2018 -0400

    Merge topic 'cmRemoveDuplicates'
    
    6d7c074055 cmAlgorithms: Speed up cmRemoveDuplicates method
    281f59536f IWYU: Define a macro to tell code it is preprocessing for iwyu
    
    Acked-by: Kitware Robot <kwrobot at kitware.com>
    Merge-request: !2101


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6d7c0740556fb06689c4d332fac685d70d83b1fe
commit 6d7c0740556fb06689c4d332fac685d70d83b1fe
Author:     Le Minh Phuc <leminhphuc10t1 at gmail.com>
AuthorDate: Wed May 23 16:43:04 2018 +0800
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Fri May 25 12:49:01 2018 -0400

    cmAlgorithms: Speed up cmRemoveDuplicates method
    
    Use a hash table instead of a sorted vector to track entries.
    
    Co-authored-by: Chu Qinghao <me at qinghao1.com>

diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index 244dc1c..c4eb62b 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -13,6 +13,7 @@
 #include <sstream>
 #include <string.h>
 #include <string>
+#include <unordered_set>
 #include <utility>
 #include <vector>
 
@@ -275,55 +276,19 @@ typename Range::const_iterator cmRemoveMatching(Range& r, MatchRange const& m)
                         ContainerAlgorithms::BinarySearcher<MatchRange>(m));
 }
 
-namespace ContainerAlgorithms {
-
-template <typename Range, typename T = typename Range::value_type>
-struct RemoveDuplicatesAPI
-{
-  typedef typename Range::const_iterator const_iterator;
-  typedef typename Range::const_iterator value_type;
-
-  static bool lessThan(value_type a, value_type b) { return *a < *b; }
-  static value_type uniqueValue(const_iterator a) { return a; }
-  template <typename It>
-  static bool valueCompare(It it, const_iterator it2)
-  {
-    return **it != *it2;
-  }
-};
-
-template <typename Range, typename T>
-struct RemoveDuplicatesAPI<Range, T*>
-{
-  typedef typename Range::const_iterator const_iterator;
-  typedef T* value_type;
-
-  static bool lessThan(value_type a, value_type b) { return a < b; }
-  static value_type uniqueValue(const_iterator a) { return *a; }
-  template <typename It>
-  static bool valueCompare(It it, const_iterator it2)
-  {
-    return *it != *it2;
-  }
-};
-}
-
 template <typename Range>
 typename Range::const_iterator cmRemoveDuplicates(Range& r)
 {
-  typedef ContainerAlgorithms::RemoveDuplicatesAPI<Range> API;
-  typedef typename API::value_type T;
-  std::vector<T> unique;
-  unique.reserve(r.size());
+  typedef typename Range::value_type T;
+  std::unordered_set<T> unique;
   std::vector<size_t> indices;
   size_t count = 0;
   const typename Range::const_iterator end = r.end();
   for (typename Range::const_iterator it = r.begin(); it != end;
        ++it, ++count) {
-    const typename std::vector<T>::iterator low = std::lower_bound(
-      unique.begin(), unique.end(), API::uniqueValue(it), API::lessThan);
-    if (low == unique.end() || API::valueCompare(low, it)) {
-      unique.insert(low, API::uniqueValue(it));
+    const typename std::unordered_set<T>::iterator occur = unique.find(*it);
+    if (occur == unique.end()) {
+      unique.insert(*it);
     } else {
       indices.push_back(count);
     }
diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h
index 150a51d..68b5ec0 100644
--- a/Source/cmFindPackageCommand.h
+++ b/Source/cmFindPackageCommand.h
@@ -6,11 +6,25 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include "cm_kwiml.h"
+#include <cstddef>
 #include <map>
 #include <set>
 #include <string>
 #include <vector>
 
+// IWYU insists we should forward-declare instead of including <functional>,
+// but we cannot forward-declare reliably because some C++ standard libraries
+// put the template in an inline namespace.
+#ifdef CMAKE_IWYU
+/* clang-format off */
+namespace std {
+  template <class T> struct hash;
+}
+/* clang-format on */
+#else
+#include <functional>
+#endif
+
 #include "cmFindCommon.h"
 
 class cmCommand;
@@ -194,6 +208,24 @@ private:
     }
   };
   std::vector<ConfigFileInfo> ConsideredConfigs;
+
+  friend struct std::hash<ConfigFileInfo>;
+};
+
+namespace std {
+
+template <>
+struct hash<cmFindPackageCommand::ConfigFileInfo>
+{
+  typedef cmFindPackageCommand::ConfigFileInfo argument_type;
+  typedef size_t result_type;
+
+  result_type operator()(argument_type const& s) const noexcept
+  {
+    result_type const h(std::hash<std::string>{}(s.filename));
+    return h;
+  }
 };
+}
 
 #endif

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=281f59536f8c16f9eacf175f8316a82f09629203
commit 281f59536f8c16f9eacf175f8316a82f09629203
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Fri May 25 12:43:26 2018 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Fri May 25 12:46:19 2018 -0400

    IWYU: Define a macro to tell code it is preprocessing for iwyu
    
    There are some cases where satisfying IWYU breaks compilation, such as
    forward-declaring the `std::hash<>` template with C++ standard libraries
    that use an inline namespace inside `std`.  Define a macro during
    include-what-you-use preprocessing so that code can adapt.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3ee67cb..e20d770 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -285,7 +285,7 @@ if(CMake_RUN_IWYU)
     message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
   endif()
   set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
-    "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
+    "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w;-DCMAKE_IWYU")
 endif()
 
 

-----------------------------------------------------------------------

Summary of changes:
 CMakeLists.txt                |    2 +-
 Source/cmAlgorithms.h         |   47 ++++++-----------------------------------
 Source/cmFindPackageCommand.h |   32 ++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 42 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list