65 Commits

Author SHA1 Message Date
Sebastian Holtermann
f71f7ce3f0 cmStringAlgorithms: Move string functions to the new cmStringAlgorithms.h
This adds the `cmStringAlgorithms.h` header and moves all string functions
from `cmAlgorithms.h` to `cmStringAlgorithms.h`.
2019-07-29 21:13:56 +02:00
Sebastian Holtermann
65d3ea2c7f cmAlgorithms: Make cmHasLiteral{Prefix,Suffix} cm::string_view based 2019-07-24 19:31:14 +02:00
Sebastian Holtermann
301f5356fd cmAlgorithms: Make cmHasPrefix and cmHasSuffix cm::string_view based
Make `cmHasPrefix`, `cmHasSuffix` and `cmStripSuffixIfExists` accept
arguments as `cm::string_view` instead of `const std::string&`.
This lets them accept literal strings without having to allocate a temporary
`std::string`.
Add variants of `cmHasPrefix`, `cmHasSuffix` and `cmStripSuffixIfExists` that
accept a single character as second argument.
2019-07-22 16:04:22 +02:00
Marc Chevrier
d9b2c7dae2 Introduce memory management helper: cm_memory.hxx 2019-07-14 15:37:30 +02:00
Sebastian Holtermann
999516478d cmAlgorithms: Add cmAppend function
The new `cmAppend` function simplifies appending ranges of values to a
`std::vector`.
2019-05-23 15:32:23 +02:00
Artur Ryt
bf1e73305a cmAlgorithms: Refactor cmRemoveDuplicates
Use an iterator-based implementation with range-based one simply
deferring to it.

Also optimize a little by storing iterators to unique values to prevent
creating value copies.
2019-03-06 08:57:47 -05:00
Regina Pfeifer
9eb0e73f46 cmRange: Move to dedicated header file 2019-02-21 08:24:25 -05:00
Brad King
50ba2f019b Merge topic 'fix-legacy-implicit-includes'
6fc3382944 Update logic for sysroot in detected implicit include directories
2ad14ef4ea cmAlgorithms: Add cmHasPrefix to match existing cmHasSuffix
557b2d6e65 Fix regression in -I/usr/include exclusion logic
017598a444 macOS: Fix addition of <sdk>/usr/include to default implicit include dirs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2957
2019-02-14 10:14:47 -05:00
Brad King
2ad14ef4ea cmAlgorithms: Add cmHasPrefix to match existing cmHasSuffix 2019-02-13 09:52:20 -05:00
Artur Ryt
15bdbec017 cmAlgorithms: Make cmRange advance/retreat safe for rvalues
In rvalue context these functions have to return cmRange
by copy instead of reference to temporary object

It allows to use ranged-for over cmMakeRange(xxx).advance(yyy)
2019-02-07 22:38:12 +01:00
Regina Pfeifer
5a0784ddea clang-tidy: Pass by value 2019-01-22 13:03:04 -05:00
Bruno Manganelli
70e245f19e cmAlgorithms: add utility functions to get signed size of containers 2018-12-27 22:29:06 +01:00
Kitware Robot
d7204e649e Revise C++ coding style using clang-format-6.0
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`.  Use `clang-format` version 6.0.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.
2018-06-01 09:53:42 -04:00
Le Minh Phuc
6d7c074055 cmAlgorithms: Speed up cmRemoveDuplicates method
Use a hash table instead of a sorted vector to track entries.

Co-authored-by: Chu Qinghao <me@qinghao1.com>
2018-05-25 12:49:01 -04:00
jrp2014
966dba5b68 cmAlgorithms: Remove unnecessary typename keyword 2018-04-05 13:42:48 -04:00
Matthias Maennich
57132765e0 Replace cmArray{Begin,End,Size} by their standard counterparts
std::{begin,end} are part of C++11, std::{cbegin,cend} are part of C++14
and an standard compliant implementation has been introduced within the
'cm' namespace: cm::{cbegin,cend}.

std::size is only part of C++17, hence exposing a compliant implementation
within namespace cm (cm::size).

where possible, the standard implementations are reused.
2017-10-23 17:51:35 +02:00
Brad King
44d3a76d4a Avoid using std::bind1st that is removed in C++17
Use a lambda instead now that we require C++11.
2017-09-23 06:49:48 -04:00
Daniel Pfeifer
2b4c32c95f clang-format: format all code as Cpp11 2017-08-30 11:07:05 -04:00
Daniel Pfeifer
4614a3b287 server: backport to C++11 2017-08-26 07:46:57 +02:00
Daniel Pfeifer
b799ca42b8 cmAlgorithms: pass std::string by const ref 2017-04-21 21:40:54 +02:00
Daniel Pfeifer
1d829c862c Use quotes for non-system includes
Automate with:

git grep -l '#include <cm_' -- Source \
  | xargs sed -i 's/#include <\(cm_.*\)>/#include "\1"/g'

git grep -l '#include <cmsys/' -- Source \
  | xargs sed -i 's/#include <\(cmsys\/.*\)>/#include "\1"/g'

git grep -l '#include <cm[A-Z]' -- Source \
  | xargs sed -i 's/#include <\(cm[A-Z].*\)>/#include "\1"/g'
2017-04-11 22:35:21 +02:00
Daniel Pfeifer
c3800e5458 cmAlgorithms: add cmEraseIf function 2017-02-10 23:04:32 +01:00
Daniel Pfeifer
7c9db8f813 clang-tidy: apply performance-unnecessary-value-param fixes 2016-12-12 14:04:12 -05:00
Daniel Pfeifer
2e620f0b38 Fix several include-what-you-use findings 2016-11-08 09:42:04 -05:00
Brad King
86578eccf2 Simplify CMake per-source license notices
Per-source copyright/license notice headers that spell out copyright holder
names and years are hard to maintain and often out-of-date or plain wrong.
Precise contributor information is already maintained automatically by the
version control tool.  Ultimately it is the receiver of a file who is
responsible for determining its licensing status, and per-source notices are
merely a convenience.  Therefore it is simpler and more accurate for
each source to have a generic notice of the license name and references to
more detailed information on copyright holders and full license terms.

Our `Copyright.txt` file now contains a list of Contributors whose names
appeared source-level copyright notices.  It also references version control
history for more precise information.  Therefore we no longer need to spell
out the list of Contributors in each source file notice.

Replace CMake per-source copyright/license notice headers with a short
description of the license and links to `Copyright.txt` and online information
available from "https://cmake.org/licensing".  The online URL also handles
cases of modules being copied out of our source into other projects, so we
can drop our notices about replacing links with full license text.

Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority
of the replacements mechanically.  Manually fix up shebang lines and trailing
newlines in a few files.  Manually update the notices in a few files that the
script does not handle.
2016-09-27 15:14:44 -04:00
Daniel Pfeifer
3838a0d5fb make sure to include cmConfigure.h before cmStandardIncludes.h 2016-09-03 08:04:22 -04:00
Nicolas Despres
8a862a4d4b Ninja: Support embedding of CMake as subninja project
Add a `CMAKE_NINJA_OUTPUT_PATH_PREFIX` variable.  When it is set, CMake
generates a `build.ninja` file suitable for embedding into another ninja
project potentially generated by an alien generator.
2016-05-17 09:34:12 -04:00
Kitware Robot
d9fd2f5402 Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.
2016-05-16 16:05:19 -04:00
Christoph Grüninger
ccb2d5c07f cmAlgorithms.h: remove superfluous semicolon after method 2016-02-01 10:47:25 -05:00
Milian Wolff
70788e9264 Remove temporary allocations when calling cmHasLiteral{Suf,Pre}fix.
When the first argument passed is a std::string, we need to take it
by const&, otherwise we copy the string and trigger a temporary
allocation. This patch removes a few 10k temporary allocations when
running the CMake daemon on the KDevelop build dir.

This hotspot was found with heaptrack.
2016-01-20 21:20:55 +01:00
Brad King
036b6ef7c4 Port CMake from cmIML to KWIML
KWIML no longer uses a configured prefix.
2015-12-18 10:02:07 -05:00
Stephen Kelly
9644a2d11c cmAlgorithms: Add cmMakeReverseIterator. 2015-07-22 21:23:50 +02:00
Stephen Kelly
514a1dff5b cmAlgorithms: Add some convenient typedefs. 2015-07-22 20:25:47 +02:00
Stephen Kelly
1fe71e2ef0 cmAlgorithms: Move Range type out of private namespace. 2015-07-22 10:58:19 -04:00
Stephen Kelly
8ea0b81d20 cmAlgorithms: Rename cmRange to cmMakeRange. 2015-07-22 10:58:19 -04:00
Brad King
18e85253c3 Merge topic 'cmRemoveDuplicates-improvement'
8701a3f4 cmRemoveDuplicates: Partially specialize the API for pointer types.
eec7091d cmRemoveDuplicates: Type-parameterize all uniq-operations
7cbafa8c cmRemoveDuplicates: Store unique iterators instead of values.
2015-03-12 15:26:37 -04:00
Brad King
15b06bc012 Merge topic 'cmAlgorithms-cleanup'
95dd238f cmRemoveDuplicates: Fix iterator -> const_iterator.
4448f175 cmInstalledFile: Move Property implementation out of line.
7916d7ba Include cmAlgorithms where it is used.
2015-03-12 15:26:35 -04:00
Stephen Kelly
8701a3f468 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.
2015-03-11 00:17:55 +01:00
Stephen Kelly
eec7091d76 cmRemoveDuplicates: Type-parameterize all uniq-operations 2015-03-11 00:17:55 +01:00
Stephen Kelly
7cbafa8c65 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@pfeifer-mail.de>
2015-03-11 00:17:55 +01:00
Stephen Kelly
95dd238f5c cmRemoveDuplicates: Fix iterator -> const_iterator. 2015-03-11 00:17:30 +01:00
Stephen Kelly
3ff95f3b0b cmAlgorithms: Add early return in cmRemoveIndices.
Avoid derefencing the iterator and segfaulting if the range
is empty.
2015-03-10 21:20:58 +01:00
Stephen Kelly
47c2da6aa8 cmAlgorithms: Cache the end iterators in algorithms. 2015-02-24 09:16:02 -05:00
Stephen Kelly
a5b10ae68a cmAlgorithms: Remove needless assignment. 2015-02-24 09:16:02 -05:00
Stephen Kelly
7fd8557f4c cmAlgorithms: Maintain the pivot iterator in cmRemoveIndices.
Avoid the algorithm of 'Schlemiel the painter' in the case of
iterators which are not RandomAccess.
2015-02-24 09:16:02 -05:00
Stephen Kelly
1f79679136 cmAlgorithms: Relax iterator requirement for cmRemoveIndices.
Require only forward iterators from the range.
2015-02-24 09:16:02 -05:00
Stephen Kelly
ba959934a6 cmAlgorithms: Make cmRemoveDuplicates work with more containers.
Remove the accidental requirement that the input range must be a
std::vector.
2015-02-24 09:16:02 -05:00
Stephen Kelly
cae45df772 cmAlgorithms: Rename template argument to RemoveN. 2015-02-24 09:16:01 -05:00
Stephen Kelly
b917f4c003 cmAlgorithms: Relax cmRemoveN requirement to FwdIter.
cmRotate already requires only FwdIter.
2015-02-24 09:16:01 -05:00
Stephen Kelly
bbc1a9788d cmAlgorithms: Add a size() to cmRange.
size() is already used by cmRemoveDuplicates, which is designed to
accept a cmRange.
2015-02-24 09:16:01 -05:00