diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/text/qanystringview.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h index 079cf751af1..856ee397daf 100644 --- a/src/corelib/text/qanystringview.h +++ b/src/corelib/text/qanystringview.h @@ -272,7 +272,7 @@ public: } [[nodiscard]] constexpr QAnyStringView sliced(qsizetype pos) const - { verify(pos, 0); auto r = *this; r.advanceData(pos); r.setSize(size() - pos); return r; } + { verify(pos, 0); auto r = *this; r.advanceData(pos); r.decreaseSize(pos); return r; } [[nodiscard]] constexpr QAnyStringView sliced(qsizetype pos, qsizetype n) const { verify(pos, n); auto r = *this; r.advanceData(pos); r.setSize(n); return r; } [[nodiscard]] constexpr QAnyStringView first(qsizetype n) const @@ -290,7 +290,7 @@ public: constexpr void truncate(qsizetype n) { verify(0, n); setSize(n); } constexpr void chop(qsizetype n) - { verify(0, n); setSize(size() - n); } + { verify(0, n); decreaseSize(n); } template <typename...Args> [[nodiscard]] inline QString arg(Args &&...args) const; @@ -361,6 +361,11 @@ private: [[nodiscard]] inline constexpr QLatin1StringView asLatin1StringView() const; [[nodiscard]] constexpr size_t charSize() const noexcept { return isUtf16() ? 2 : 1; } constexpr void setSize(qsizetype sz) noexcept { m_size = size_t(sz) | tag(); } + constexpr void decreaseSize(qsizetype delta) noexcept + { + delta <<= SizeShift; + m_size -= delta; + } constexpr void advanceData(qsizetype delta) noexcept { m_data_utf8 += delta * charSize(); } Q_ALWAYS_INLINE constexpr void verify([[maybe_unused]] qsizetype pos = 0, |
