From f1c9f8e628eb87a861aca68f72678f038a794221 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Wed, 23 Sep 2020 13:55:18 +0200 Subject: [PATCH] QmlJS: Do not change strings referenced by QStringView QStringRef is stable under reallocations of it's string()), while QStringView is not. This adds the missing changes from qtdeclarative 1b10ce6a08e. Task-number: QDS-2825 Change-Id: I120a34153424ea514abaa783f1a617ef2f8b4cf4 Reviewed-by: Eike Ziller --- src/libs/qmljs/parser/qmljsengine_p.cpp | 9 +++++---- src/libs/qmljs/parser/qmljsengine_p.h | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libs/qmljs/parser/qmljsengine_p.cpp b/src/libs/qmljs/parser/qmljsengine_p.cpp index 29456b8156e..44f03a1a740 100644 --- a/src/libs/qmljs/parser/qmljsengine_p.cpp +++ b/src/libs/qmljs/parser/qmljsengine_p.cpp @@ -133,13 +133,14 @@ MemoryPool *Engine::pool() QStringView Engine::newStringRef(const QString &text) { - const int pos = _extraCode.length(); - _extraCode += text; - return Utils::midView(_extraCode, pos, text.length()); + _extraCode.append(text); + return QStringView{_extraCode.last()}; } QStringView Engine::newStringRef(const QChar *chars, int size) -{ return newStringRef(QString(chars, size)); } +{ + return newStringRef(QString(chars, size)); +} } // end of namespace QmlJS diff --git a/src/libs/qmljs/parser/qmljsengine_p.h b/src/libs/qmljs/parser/qmljsengine_p.h index acef6c015b6..a6e8ad272f9 100644 --- a/src/libs/qmljs/parser/qmljsengine_p.h +++ b/src/libs/qmljs/parser/qmljsengine_p.h @@ -37,14 +37,16 @@ // #include "qmljsglobal_p.h" -#include "qmljs/parser/qmljssourcelocation_p.h" #include "qmljs/parser/qmljsmemorypool_p.h" +#include "qmljs/parser/qmljssourcelocation_p.h" +#include + +#include #include #include -#include QT_QML_BEGIN_NAMESPACE namespace QmlJS { @@ -84,7 +86,7 @@ class QML_PARSER_EXPORT Engine Directives *_directives; MemoryPool _pool; QList _comments; - QString _extraCode; + QStringList _extraCode; QString _code; public: @@ -107,9 +109,7 @@ public: inline QStringView midRef(int position, int size) { - if (position + size > _code.size()) - return QStringView(_code).mid(position); - return QStringView(_code).mid(position, size); + return Utils::midView(_code, position, size); } QStringView newStringRef(const QString &s);