mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 10:15:43 +08:00
Delegate parts of CSequence to a non-template implementation
To reduce build time.
This commit is contained in:
@@ -37,4 +37,14 @@
|
|||||||
# define BLACKMISC_EXPORT_DECLARE_TEMPLATE
|
# define BLACKMISC_EXPORT_DECLARE_TEMPLATE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \def BLACK_NO_INLINE
|
||||||
|
* Prevent function inlining
|
||||||
|
*/
|
||||||
|
#ifdef Q_CC_MSVC
|
||||||
|
#define BLACK_NO_INLINE __declspec(noinline)
|
||||||
|
#else
|
||||||
|
#define BLACK_NO_INLINE __attribute__((noinline))
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
31
src/blackmisc/sequence.cpp
Normal file
31
src/blackmisc/sequence.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/* Copyright (C) 2021
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||||
|
* or distributed except according to the terms contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
|
#include "blackmisc/sequence.h"
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
|
namespace BlackMisc::Private
|
||||||
|
{
|
||||||
|
QVector<int> findIndices(int size, const std::function<bool(int)> &predicate)
|
||||||
|
{
|
||||||
|
QVector<int> result(size);
|
||||||
|
std::iota(result.begin(), result.end(), 0);
|
||||||
|
result.erase(std::remove_if(result.begin(), result.end(), std::not_fn(predicate)), result.end());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<int> sortIndices(int size, const std::function<bool(int, int)> &cmp)
|
||||||
|
{
|
||||||
|
QVector<int> result(size);
|
||||||
|
std::iota(result.begin(), result.end(), 0);
|
||||||
|
std::sort(result.begin(), result.end(), cmp);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,12 +14,14 @@
|
|||||||
#include "blackmisc/containerbase.h"
|
#include "blackmisc/containerbase.h"
|
||||||
#include "blackmisc/mixin/mixinicon.h"
|
#include "blackmisc/mixin/mixinicon.h"
|
||||||
#include "blackmisc/mixin/mixindatastream.h"
|
#include "blackmisc/mixin/mixindatastream.h"
|
||||||
|
#include "blackmisc/blackmiscexport.h"
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
//! \cond
|
//! \cond
|
||||||
#define BLACK_TEMPLATE_SEQUENCE_MIXINS(NS, T, List, Extern) \
|
#define BLACK_TEMPLATE_SEQUENCE_MIXINS(NS, T, List, Extern) \
|
||||||
@@ -63,6 +65,15 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
namespace Private
|
||||||
|
{
|
||||||
|
//! \private Decouple finding from value type.
|
||||||
|
BLACKMISC_EXPORT BLACK_NO_INLINE QVector<int> findIndices(int size, const std::function<bool(int)> &predicate);
|
||||||
|
|
||||||
|
//! \private Decouple sorting from value type.
|
||||||
|
BLACKMISC_EXPORT BLACK_NO_INLINE QVector<int> sortIndices(int size, const std::function<bool(int, int)> &cmp);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Generic sequential container with value semantics.
|
* Generic sequential container with value semantics.
|
||||||
* \tparam T the type of elements contained.
|
* \tparam T the type of elements contained.
|
||||||
@@ -306,6 +317,20 @@ namespace BlackMisc
|
|||||||
//! Return an iterator to the first element equal to the given object, or the end iterator if not found. O(n).
|
//! Return an iterator to the first element equal to the given object, or the end iterator if not found. O(n).
|
||||||
const_iterator find(const T &object) const { return std::find(cbegin(), cend(), object); }
|
const_iterator find(const T &object) const { return std::find(cbegin(), cend(), object); }
|
||||||
|
|
||||||
|
using CContainerBase<CSequence<T>>::findBy;
|
||||||
|
|
||||||
|
//! \copydoc BlackMisc::CRangeBase::findBy
|
||||||
|
template <class Predicate>
|
||||||
|
CSequence findBy(Predicate p) const
|
||||||
|
{
|
||||||
|
QVector<T> found;
|
||||||
|
for (int i : Private::findIndices(size(), [&p, this](int i) { return p((*this)[i]); }))
|
||||||
|
{
|
||||||
|
found.push_back((*this)[i]);
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
//! Modify by applying a value map to each element for which a given predicate returns true.
|
//! Modify by applying a value map to each element for which a given predicate returns true.
|
||||||
//! \return The number of elements modified.
|
//! \return The number of elements modified.
|
||||||
template <class Predicate, class VariantMap>
|
template <class Predicate, class VariantMap>
|
||||||
@@ -460,7 +485,13 @@ namespace BlackMisc
|
|||||||
//! In-place sort by a given comparator predicate.
|
//! In-place sort by a given comparator predicate.
|
||||||
template <class Predicate> void sort(Predicate p)
|
template <class Predicate> void sort(Predicate p)
|
||||||
{
|
{
|
||||||
std::sort(begin(), end(), p);
|
QVector<T> temp;
|
||||||
|
temp.reserve(size());
|
||||||
|
for (int i : Private::sortIndices(size(), [&p, this](int a, int b) { return p((*this)[a], (*this)[b]); }))
|
||||||
|
{
|
||||||
|
temp.push_back(std::move((*this)[i]));
|
||||||
|
}
|
||||||
|
m_impl = std::move(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! In-place sort by some particular key(s).
|
//! In-place sort by some particular key(s).
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ BLACK_DEFINE_SEQUENCE_MIXINS(BlackMisc::Simulation::FsCommon, CAircraftCfgEntrie
|
|||||||
|
|
||||||
namespace BlackMisc::Simulation::FsCommon
|
namespace BlackMisc::Simulation::FsCommon
|
||||||
{
|
{
|
||||||
|
CAircraftCfgEntriesList::CAircraftCfgEntriesList() = default;
|
||||||
|
|
||||||
|
CAircraftCfgEntriesList::CAircraftCfgEntriesList(const CSequence<CAircraftCfgEntries>& other) : CSequence(other) {}
|
||||||
|
|
||||||
bool CAircraftCfgEntriesList::containsModelWithTitle(const QString &title, Qt::CaseSensitivity caseSensitivity)
|
bool CAircraftCfgEntriesList::containsModelWithTitle(const QString &title, Qt::CaseSensitivity caseSensitivity)
|
||||||
{
|
{
|
||||||
if (title.isEmpty()) { return false; }
|
if (title.isEmpty()) { return false; }
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ namespace BlackMisc::Simulation::FsCommon
|
|||||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CAircraftCfgEntriesList)
|
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CAircraftCfgEntriesList)
|
||||||
using CSequence::CSequence;
|
using CSequence::CSequence;
|
||||||
|
|
||||||
|
//! Default constructor.
|
||||||
|
CAircraftCfgEntriesList();
|
||||||
|
|
||||||
|
//! Construct from a base class object.
|
||||||
|
CAircraftCfgEntriesList(const CSequence<CAircraftCfgEntries> &other);
|
||||||
|
|
||||||
//! Contains model with title?
|
//! Contains model with title?
|
||||||
bool containsModelWithTitle(const QString &title, Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive);
|
bool containsModelWithTitle(const QString &title, Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
|||||||
@@ -13,14 +13,6 @@
|
|||||||
|
|
||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
|
|
||||||
//! \cond
|
|
||||||
#ifdef Q_CC_MSVC
|
|
||||||
#define BLACK_NO_INLINE __declspec(noinline)
|
|
||||||
#else
|
|
||||||
#define BLACK_NO_INLINE __attribute__((noinline))
|
|
||||||
#endif
|
|
||||||
//! \endcond
|
|
||||||
|
|
||||||
namespace BlackMisc::Private
|
namespace BlackMisc::Private
|
||||||
{
|
{
|
||||||
//! \private Do nothing.
|
//! \private Do nothing.
|
||||||
|
|||||||
Reference in New Issue
Block a user