summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qversionnumber.cpp17
-rw-r--r--src/corelib/tools/qversionnumber.h16
2 files changed, 27 insertions, 6 deletions
diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp
index 4aa8cdd346..38977c3db8 100644
--- a/src/corelib/tools/qversionnumber.cpp
+++ b/src/corelib/tools/qversionnumber.cpp
@@ -120,6 +120,13 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn template <qsizetype N> QVersionNumber::QVersionNumber(const QVarLengthArray<int, N> &seg)
+ \since 6.4
+
+ Constructs a version number from the list of numbers contained in \a seg.
+*/
+
+/*!
\fn bool QVersionNumber::isNull() const
Returns \c true if there are zero numerical segments, otherwise returns
@@ -421,7 +428,13 @@ QString QVersionNumber::toString() const
static QVersionNumber from_string(QLatin1String string, qsizetype *suffixIndex)
{
- QList<int> seg;
+ // 32 should be more than enough, and, crucially, it means we're allocating
+ // not more (and often less) often when compared with direct QList usage
+ // for all possible segment counts (under the constraint that we don't want
+ // to keep more capacity around for the lifetime of the resulting
+ // QVersionNumber than required), esp. in the common case where the inline
+ // storage can be used.
+ QVarLengthArray<int, 32> seg;
const char *start = string.begin();
const char *end = start;
@@ -441,7 +454,7 @@ static QVersionNumber from_string(QLatin1String string, qsizetype *suffixIndex)
if (suffixIndex)
*suffixIndex = lastGoodEnd - string.begin();
- return QVersionNumber(std::move(seg));
+ return QVersionNumber(seg);
}
static QVersionNumber from_string(q_no_char8_t::QUtf8StringView string, qsizetype *suffixIndex)
diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h
index ad8367c135..f00ce36437 100644
--- a/src/corelib/tools/qversionnumber.h
+++ b/src/corelib/tools/qversionnumber.h
@@ -141,12 +141,15 @@ class QVersionNumber
else
pointer_segments = new QList<int>(std::move(seg));
}
- SegmentStorage(std::initializer_list<int> args)
+ explicit SegmentStorage(std::initializer_list<int> args)
+ : SegmentStorage(args.begin(), args.end()) {}
+
+ explicit SegmentStorage(const int *first, const int *last)
{
- if (dataFitsInline(std::data(args), args.size())) {
- setInlineData(std::data(args), args.size());
+ if (dataFitsInline(first, last - first)) {
+ setInlineData(first, last - first);
} else {
- pointer_segments = new QList<int>(args);
+ pointer_segments = new QList<int>(first, last);
}
}
@@ -234,6 +237,11 @@ public:
: m_segments(args)
{}
+ template <qsizetype N>
+ explicit QVersionNumber(const QVarLengthArray<int, N> &sec)
+ : m_segments(sec.begin(), sec.end())
+ {}
+
inline explicit QVersionNumber(int maj)
{ m_segments.setSegments(1, maj); }