[Cmake-commits] CMake branch, next, updated. v3.2.0-1001-gfefa015
Stephen Kelly
steveire at gmail.com
Tue Mar 10 19:18:58 EDT 2015
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, next has been updated
via fefa0152b87e56facf57e87f78f1acb78e87f8b4 (commit)
via 8701a3f468a4fb684442a8a9c5d4c8d15c72eb7b (commit)
via eec7091d76fc3db6535eec3f78fd2585b9c0c38a (commit)
via 7cbafa8c65751d2eda7a17753c384da1fc91f695 (commit)
from 60a0124433790253adab5901ca1c068903b517d7 (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 -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fefa0152b87e56facf57e87f78f1acb78e87f8b4
commit fefa0152b87e56facf57e87f78f1acb78e87f8b4
Merge: 60a0124 8701a3f
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Mar 10 19:18:56 2015 -0400
Commit: CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Tue Mar 10 19:18:56 2015 -0400
Merge topic 'cmRemoveDuplicates-improvement' into next
8701a3f4 cmRemoveDuplicates: Partially specialize the API for pointer types.
eec7091d cmRemoveDuplicates: Type-parameterize all uniq-operations
7cbafa8c cmRemoveDuplicates: Store unique iterators instead of values.
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8701a3f468a4fb684442a8a9c5d4c8d15c72eb7b
commit 8701a3f468a4fb684442a8a9c5d4c8d15c72eb7b
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Mar 8 09:43:11 2015 +0100
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Mar 11 00:17:55 2015 +0100
cmRemoveDuplicates: Partially specialize the API for pointer types.
If de-duplicating a container of pointers, there is no need to
store iterators to them, as that is just more 'pointer chasing'.
Store the pointers themselves and use API which compares the pointers
in the specialization.
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index 5504fee..0cf7701 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -263,7 +263,7 @@ typename Range::const_iterator cmRemoveMatching(Range &r, MatchRange const& m)
namespace ContainerAlgorithms {
-template<typename Range>
+template<typename Range, typename T = typename Range::value_type>
struct RemoveDuplicatesAPI
{
typedef typename Range::const_iterator const_iterator;
@@ -275,6 +275,18 @@ struct RemoveDuplicatesAPI
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>
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=eec7091d76fc3db6535eec3f78fd2585b9c0c38a
commit eec7091d76fc3db6535eec3f78fd2585b9c0c38a
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Mar 1 21:57:16 2015 +0100
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Mar 11 00:17:55 2015 +0100
cmRemoveDuplicates: Type-parameterize all uniq-operations
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index 1b7029b..5504fee 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -176,12 +176,6 @@ private:
Range const& m_range;
};
-struct IterLess
-{
- template<typename It>
- bool operator()(It const& a, It const& b) const { return *a < *b; }
-};
-
}
template<typename Iter1, typename Iter2>
@@ -267,10 +261,27 @@ typename Range::const_iterator cmRemoveMatching(Range &r, MatchRange const& m)
ContainerAlgorithms::BinarySearcher<MatchRange>(m));
}
+namespace ContainerAlgorithms {
+
+template<typename Range>
+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 Range::const_iterator cmRemoveDuplicates(Range& r)
{
- typedef typename Range::const_iterator T;
+ typedef typename ContainerAlgorithms::RemoveDuplicatesAPI<Range> API;
+ typedef typename API::value_type T;
std::vector<T> unique;
unique.reserve(r.size());
std::vector<size_t> indices;
@@ -280,11 +291,11 @@ typename Range::const_iterator cmRemoveDuplicates(Range& r)
it != end; ++it, ++count)
{
const typename std::vector<T>::iterator low =
- std::lower_bound(unique.begin(), unique.end(), it,
- ContainerAlgorithms::IterLess());
- if (low == unique.end() || **low != *it)
+ std::lower_bound(unique.begin(), unique.end(),
+ API::uniqueValue(it), API::lessThan);
+ if (low == unique.end() || API::valueCompare(low, it))
{
- unique.insert(low, it);
+ unique.insert(low, API::uniqueValue(it));
}
else
{
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7cbafa8c65751d2eda7a17753c384da1fc91f695
commit 7cbafa8c65751d2eda7a17753c384da1fc91f695
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Mar 1 21:53:04 2015 +0100
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Mar 11 00:17:55 2015 +0100
cmRemoveDuplicates: Store unique iterators instead of values.
There is no need to copy all of the values in the container in
order to determine uniqueness. Iterators can be stored instead
and can be used with standard algorithms with custom comparison
methods.
This also means that we use less space in case the value_type size
is greater than sizeof(iterator). That is common for std::string
which may require up to 32 bytes (libstdc++ 5.0 and MSVC at least).
With libstdc++ 4.9 and older, std::string is 8 bytes, so we likely
don't gain anything here.
Inspired-by: Daniel Pfeifer <daniel at pfeifer-mail.de>
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index f032de7..1b7029b 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -176,6 +176,12 @@ private:
Range const& m_range;
};
+struct IterLess
+{
+ template<typename It>
+ bool operator()(It const& a, It const& b) const { return *a < *b; }
+};
+
}
template<typename Iter1, typename Iter2>
@@ -264,8 +270,8 @@ typename Range::const_iterator cmRemoveMatching(Range &r, MatchRange const& m)
template<typename Range>
typename Range::const_iterator cmRemoveDuplicates(Range& r)
{
- typedef std::vector<typename Range::value_type> UniqueVector;
- UniqueVector unique;
+ typedef typename Range::const_iterator T;
+ std::vector<T> unique;
unique.reserve(r.size());
std::vector<size_t> indices;
size_t count = 0;
@@ -273,11 +279,12 @@ typename Range::const_iterator cmRemoveDuplicates(Range& r)
for(typename Range::const_iterator it = r.begin();
it != end; ++it, ++count)
{
- const typename UniqueVector::iterator low =
- std::lower_bound(unique.begin(), unique.end(), *it);
- if (low == unique.end() || *low != *it)
+ const typename std::vector<T>::iterator low =
+ std::lower_bound(unique.begin(), unique.end(), it,
+ ContainerAlgorithms::IterLess());
+ if (low == unique.end() || **low != *it)
{
- unique.insert(low, *it);
+ unique.insert(low, it);
}
else
{
-----------------------------------------------------------------------
Summary of changes:
hooks/post-receive
--
CMake
More information about the Cmake-commits
mailing list