forked from qt-creator/qt-creator
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 <eike.ziller@qt.io>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 <qmljs/qmljsconstants.h>
|
||||
|
||||
#include <utils/porting.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QSet>
|
||||
|
||||
#include <qmljs/qmljsconstants.h>
|
||||
QT_QML_BEGIN_NAMESPACE
|
||||
|
||||
namespace QmlJS {
|
||||
@@ -84,7 +86,7 @@ class QML_PARSER_EXPORT Engine
|
||||
Directives *_directives;
|
||||
MemoryPool _pool;
|
||||
QList<SourceLocation> _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);
|
||||
|
||||
Reference in New Issue
Block a user