-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
catkin pkg config template: performance fix for pack/unpack/append
These algorithms may be used O(M^2) times where M is the level of rospackage nesting, and each pack/unpack/append algorithm complexity are O(N^2)/O(N)/O(N^2) where N is libraries count. The fix allows to reduce them to O(1) complexity if we only consider amount of cmake statements executed. Notes regarding REMOVE_DUPLICATES in list_append_unique and list_append_deduplicate are incorrect, in case of: - list_append_unique: REMOVE_DUPLICATES uses set/unordered_set to remember encountered items, all output items are written in order, so the algorithm is "stable", it doesn't shuffle elements - list_append_deduplicate: REMOVE_DUPLICATES is improper here, as it removes duplicates from the added element list, not the added-to element list, not due to it's "unstability" as note suggests 3.0.2: https://github.com/Kitware/CMake/blob/v3.0.2/Source/cmListCommand.cxx#L480-L493 3.19.6: https://github.com/Kitware/CMake/blob/v3.19.6/Source/cmAlgorithms.h#L120-L130
- Loading branch information
1 parent
a9672d7
commit 03b9647
Showing
4 changed files
with
12 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
# | ||
# Append elements to a list if they are not already in the list. | ||
# | ||
# .. note:: Using CMake's ``list(APPEND ..)`` and | ||
# ``list(REMOVE_DUPLICATES ..)`` is not sufficient since its | ||
# implementation uses a set internally which makes the operation | ||
# unstable. | ||
# | ||
macro(list_append_unique listname) | ||
foreach(_item ${ARGN}) | ||
list(FIND ${listname} ${_item} _index) | ||
if(_index EQUAL -1) | ||
list(APPEND ${listname} ${_item}) | ||
endif() | ||
endforeach() | ||
if(NOT "${ARGN}" STREQUAL "") | ||
list(APPEND ${listname} ${ARGN}) | ||
list(REMOVE_DUPLICATES ${listname}) | ||
endif() | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters