diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2020-09-05 16:32:33 +0200 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2020-09-07 09:13:31 +0000 |
commit | e64ad82de3130178aa21e1945aebe05e22f2bae8 (patch) | |
tree | f9509caf06f6827db825b63302d657a5d40a1b79 /src/lib | |
parent | 15a0dfea97021bc6769cf2866a021b778b99307f (diff) | |
download | qbs-e64ad82de3130178aa21e1945aebe05e22f2bae8.tar.gz |
Use stl algorithms for filtering in mergeExportItems
It makes the intention clearer than a loop that does 2 actions
simultaneously and is also a bit faster since we do not shift the tail
of the list after removing an item.
Change-Id: Ia39e972a6a9f83d5c352b2021246c5839b676f7f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/corelib/language/moduleloader.cpp | 13 | ||||
-rw-r--r-- | src/lib/corelib/tools/stlutils.h | 7 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp index c00fae6a0..d099c72a9 100644 --- a/src/lib/corelib/language/moduleloader.cpp +++ b/src/lib/corelib/language/moduleloader.cpp @@ -1975,15 +1975,10 @@ bool ModuleLoader::mergeExportItems(const ProductContext &productContext) { std::vector<Item *> exportItems; QList<Item *> children = productContext.item->children(); - for (int i = 0; i < children.size();) { - Item * const child = children.at(i); - if (child->type() == ItemType::Export) { - exportItems.push_back(child); - children.removeAt(i); - } else { - ++i; - } - } + + auto isExport = [](Item *item) { return item->type() == ItemType::Export; }; + std::copy_if(children.cbegin(), children.cend(), std::back_inserter(exportItems), isExport); + qbs::Internal::removeIf(children, isExport); // Note that we do not return if there are no Export items: The "merged" item becomes the // "product module", which always needs to exist, regardless of whether the product sources diff --git a/src/lib/corelib/tools/stlutils.h b/src/lib/corelib/tools/stlutils.h index 5c21c0672..63b9c098e 100644 --- a/src/lib/corelib/tools/stlutils.h +++ b/src/lib/corelib/tools/stlutils.h @@ -93,6 +93,13 @@ void removeAll(C &container, const typename C::value_type &v) std::end(container)); } +template <typename C, typename Pred> +void removeIf(C &container, const Pred &pred) +{ + container.erase(std::remove_if(std::begin(container), std::end(container), pred), + std::end(container)); +} + template <class Container, class UnaryPredicate> bool any_of(const Container &container, const UnaryPredicate &predicate) { |