summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qoffsetstringarray_p.h
diff options
context:
space:
mode:
authorMikhail Svetkin <mikhail.svetkin@qt.io>2018-08-28 15:56:09 +0200
committerMikhail Svetkin <mikhail.svetkin@qt.io>2018-08-28 14:42:46 +0000
commit6b4e603c62c71593cadb69fee4cf6e6f4555f7d7 (patch)
treeafaf9259c2846c408d24b6ddb9838de088e20763 /src/corelib/tools/qoffsetstringarray_p.h
parentfde0adc3c791f47fff88fbc4c5128e344f307466 (diff)
corelib/tools: Fix auto detection of QOffsetStringArray::m_offset type
The previous implementation wrongly calculated the necessary data type to hold the offset indexes. It looked at the amount of elements, but instead we should look at value for the last element in the offset array Change-Id: I84c6985dc3c329df3bbc5a14f9789170877b65bb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qoffsetstringarray_p.h')
-rw-r--r--src/corelib/tools/qoffsetstringarray_p.h21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/corelib/tools/qoffsetstringarray_p.h b/src/corelib/tools/qoffsetstringarray_p.h
index a1117b1d47..ff195965ec 100644
--- a/src/corelib/tools/qoffsetstringarray_p.h
+++ b/src/corelib/tools/qoffsetstringarray_p.h
@@ -62,26 +62,23 @@ namespace QtPrivate {
template<int N, int O, int I, int ... Idx>
struct OffsetSequenceHelper : OffsetSequenceHelper<N - 1, O + I, Idx..., O> { };
-template<int O, int I, int ... Idx>
-struct OffsetSequenceHelper<0, O, I, Idx...> : IndexesList<O, Idx...>
+template<int Last, int I, int S, int ... Idx>
+struct OffsetSequenceHelper<1, Last, I, S, Idx...> : IndexesList<Last + I, Idx..., Last>
{
- static const constexpr auto Length = O;
-};
-
-template<int I, int ... Idx>
-struct OffsetSequence : OffsetSequenceHelper<sizeof ... (Idx) + 1, 0, I, Idx..., 0>
-{
- static const constexpr auto Count = sizeof ... (Idx) + 1;
+ static const constexpr auto Length = Last + I;
using Type = typename QConditional<
- Count <= std::numeric_limits<quint8>::max() + 1,
+ Last <= std::numeric_limits<quint8>::max(),
quint8,
typename QConditional<
- Count <= std::numeric_limits<quint16>::max() + 1,
+ Last <= std::numeric_limits<quint16>::max(),
quint16,
int>::Type
>::Type;
};
+template<int ... Idx>
+struct OffsetSequence : OffsetSequenceHelper<sizeof ... (Idx), 0, Idx..., 0> { };
+
template<int N>
struct StaticString
{
@@ -168,7 +165,7 @@ public:
}
constexpr inline const char *str() const { return m_string; }
- constexpr inline const int *offsets() const { return m_offsets; }
+ constexpr inline const T *offsets() const { return m_offsets; }
constexpr inline int count() const { return SizeOffsets; };
static constexpr const auto sizeString = SizeString;