diff options
author | Marc Mutz <[email protected]> | 2022-09-05 09:05:01 +0200 |
---|---|---|
committer | Thiago Macieira <[email protected]> | 2024-08-14 12:28:48 -0700 |
commit | e3fe3997ebd2baaafdfa7aa3c1eb95e8048268f8 (patch) | |
tree | a0e77f43530eab5641dfd1c31d92ca11f4afb053 | |
parent | 25b0580ec788a39ffa06c98779faa8d1aeec9b80 (diff) |
QOffsetStringArray: simplify makeOffsetStringArray()
Instead of building two arrays, a short one for size_t, and then a
full-length one for the final narrowed MinifiedOffsetType, construct
the final array directly.
This should also speed up compiling qOffsetStringArray() expressions,
Clang's -ftime-trace, for ninja tst_qoffsetstringarray, with a dirty
qoffsetstringarray_p.h (which isn't included in the PCH, so only
recompiles TUs that actually include it) shows a slight improvement:
- 37 ms: qOffsetStringArray<$> (7 times, avg 5 ms)
+ 35 ms: qOffsetStringArray<$> (7 times, avg 5 ms)
I had to disable one static_assert because it looks to be running over
some GCC limitation and concluding the array is not constexpr (even
though it is).
qhttpheaders.cpp:486:29: error: non-constant condition for static assertion
qhttpheaders.cpp:486:29: error: the value of ‘headerNames’ is not usable in a constant expression
Change-Id: I0d6109645075e5b533391ea04ea845538ad496fe
Reviewed-by: Ahmad Samir <[email protected]>
-rw-r--r-- | src/corelib/tools/qoffsetstringarray_p.h | 17 | ||||
-rw-r--r-- | src/network/access/qhttpheaders.cpp | 2 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/corelib/tools/qoffsetstringarray_p.h b/src/corelib/tools/qoffsetstringarray_p.h index e022024a53a..63e901caf1a 100644 --- a/src/corelib/tools/qoffsetstringarray_p.h +++ b/src/corelib/tools/qoffsetstringarray_p.h @@ -141,21 +141,18 @@ template <typename Char, size_t N> struct StaticString template <typename Char, typename StringExtractor, typename... T> constexpr auto makeOffsetStringArray(StringExtractor extractString, const T &... entries) { - constexpr size_t Count = sizeof...(T); constexpr size_t StringLength = (sizeof(extractString(T{})) + ...) / sizeof(Char); - using MinifiedOffsetType = decltype(QtPrivate::minifyValue<StringLength>()); - - size_t offset = 0; - std::array fullOffsetList = { offset += (sizeof(extractString(T{})) / sizeof(Char))... }; + using OffsetType = decltype(QtPrivate::minifyValue<StringLength>()); // prepend the first offset (zero) pointing to the *start* of the first element - std::array<MinifiedOffsetType, Count + 1> minifiedOffsetList = {}; - q20::transform(fullOffsetList.begin(), fullOffsetList.end(), - minifiedOffsetList.begin() + 1, - [] (auto e) { return MinifiedOffsetType(e); }); + size_t offset = 0; + std::array offsetList = { + OffsetType(0), + OffsetType(offset += sizeof(extractString(T{})) / sizeof(Char))... + }; std::array staticString = QtPrivate::makeStaticString<Char, StringLength>(extractString, entries...); - return QOffsetStringArray(staticString, minifiedOffsetList); + return QOffsetStringArray(staticString, offsetList); } } // namespace QtPrivate diff --git a/src/network/access/qhttpheaders.cpp b/src/network/access/qhttpheaders.cpp index e988f098b55..1528b02e259 100644 --- a/src/network/access/qhttpheaders.cpp +++ b/src/network/access/qhttpheaders.cpp @@ -483,9 +483,11 @@ static constexpr quint8 orderedHeaderNameIndexes[] = { 171, // x-frame-options }; static_assert(std::size(orderedHeaderNameIndexes) == size_t(headerNames.count())); +#if !defined(Q_CC_GNU_ONLY) || Q_CC_GNU_ONLY >= 1000 static_assert(q20::is_sorted(std::begin(orderedHeaderNameIndexes), std::end(orderedHeaderNameIndexes), ByIndirectHeaderName{})); +#endif /*! \enum QHttpHeaders::WellKnownHeader |