Skip to content

Commit

Permalink
Remove more QByteArray<->QString conversions
Browse files Browse the repository at this point in the history
Prefer to store types as QStrings. It's only when we manipulate
raw (compiled, meta-)data that utf conversion is needed.

Change-Id: Ie138a69c9a409804e1b90b21c1d60dedea35bddb
Reviewed-on: http://codereview.qt-project.org/5781
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
  • Loading branch information
Kent Hansen authored and Qt by Nokia committed Sep 29, 2011
1 parent 15a52c1 commit bcc9a4b
Show file tree
Hide file tree
Showing 27 changed files with 73 additions and 73 deletions.
Expand Up @@ -372,7 +372,7 @@ QDeclarativeEngineDebugService::objectData(QObject *object)

QDeclarativeType *type = QDeclarativeMetaType::qmlType(object->metaObject());
if (type) {
QString typeName = QLatin1String(type->qmlTypeName());
QString typeName = type->qmlTypeName();
int lastSlash = typeName.lastIndexOf(QLatin1Char('/'));
rv.objectType = lastSlash < 0 ? typeName : typeName.mid(lastSlash+1);
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/declarative/qml/qdeclarativecompiler.cpp
Expand Up @@ -2235,7 +2235,7 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeScript::Pro
QDeclarativeScript::Object *root = v->object;
QDeclarativeScript::Object *component = pool->New<Object>();
component->type = componentTypeRef();
component->typeName = "Qt/Component";
component->typeName = QStringLiteral("Qt/Component");
component->metatype = &QDeclarativeComponent::staticMetaObject;
component->location = root->location;
QDeclarativeScript::Value *componentValue = pool->New<Value>();
Expand Down Expand Up @@ -2294,7 +2294,7 @@ bool QDeclarativeCompiler::buildPropertyOnAssignment(QDeclarativeScript::Propert
buildDynamicMeta(baseObj, ForceCreation);
v->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor;
} else {
COMPILE_EXCEPTION(v, tr("\"%1\" cannot operate on \"%2\"").arg(QString::fromUtf8(v->object->typeName)).arg(prop->name().toString()));
COMPILE_EXCEPTION(v, tr("\"%1\" cannot operate on \"%2\"").arg(v->object->typeName).arg(prop->name().toString()));
}

return true;
Expand Down Expand Up @@ -2360,7 +2360,7 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop
unit->imports().resolveType(typeName, &type, 0, 0, 0, 0);

//handle enums on value types (where obj->typeName is empty)
QByteArray objTypeName = obj->typeName;
QString objTypeName = obj->typeName;
if (objTypeName.isEmpty()) {
QDeclarativeType *objType = toQmlType(obj);
if (objType)
Expand Down Expand Up @@ -2429,10 +2429,10 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const
return -1;
}

const QMetaObject *QDeclarativeCompiler::resolveType(const QByteArray& name) const
const QMetaObject *QDeclarativeCompiler::resolveType(const QString& name) const
{
QDeclarativeType *qmltype = 0;
if (!unit->imports().resolveType(QString::fromUtf8(name), &qmltype, 0, 0, 0, 0))
if (!unit->imports().resolveType(name, &qmltype, 0, 0, 0, 0))
return 0;
if (!qmltype)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativecompiler_p.h
Expand Up @@ -278,7 +278,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeCompiler
static bool isSignalPropertyName(const QHashedStringRef &);

int evaluateEnum(const QByteArray& script) const; // for QDeclarativeCustomParser::evaluateEnum
const QMetaObject *resolveType(const QByteArray& name) const; // for QDeclarativeCustomParser::resolveType
const QMetaObject *resolveType(const QString& name) const; // for QDeclarativeCustomParser::resolveType
int rewriteBinding(const QString& expression, const QString& name); // for QDeclarativeCustomParser::rewriteBinding

private:
Expand Down
6 changes: 3 additions & 3 deletions src/declarative/qml/qdeclarativecomponent.cpp
Expand Up @@ -91,16 +91,16 @@ static inline QString buildTypeNameForDebug(const QMetaObject *metaObject)
static const QChar underscore(QLatin1Char('_'));
static const QChar asterisk(QLatin1Char('*'));
QDeclarativeType *type = QDeclarativeMetaType::qmlType(metaObject);
QString typeName = type ? QLatin1String(type->qmlTypeName()) : QLatin1String(metaObject->className());
QString typeName = type ? type->qmlTypeName() : QString::fromUtf8(metaObject->className());
if (!type) {
//### optimize further?
int marker = typeName.indexOf(qmlMarker);
if (marker != -1 && marker < typeName.count() - 1) {
if (typeName[marker + 1] == underscore) {
const QString className = typeName.left(marker) + asterisk;
type = QDeclarativeMetaType::qmlType(QMetaType::type(className.toLatin1()));
type = QDeclarativeMetaType::qmlType(QMetaType::type(className.toUtf8()));
if (type)
typeName = QLatin1String(type->qmlTypeName());
typeName = type->qmlTypeName();
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/declarative/qml/qdeclarativecustomparser.cpp
Expand Up @@ -114,7 +114,7 @@ QDeclarativeCustomParserProperty
QDeclarativeCustomParserNodePrivate::fromProperty(QDeclarativeScript::Property *p)
{
QDeclarativeCustomParserProperty prop;
prop.d->name = p->name().toUtf8();
prop.d->name = p->name().toString();
prop.d->isList = p->values.isMany();
prop.d->location = p->location.start;

Expand Down Expand Up @@ -164,7 +164,7 @@ QDeclarativeCustomParserNode::~QDeclarativeCustomParserNode()
delete d; d = 0;
}

QByteArray QDeclarativeCustomParserNode::name() const
QString QDeclarativeCustomParserNode::name() const
{
return d->name;
}
Expand Down Expand Up @@ -204,7 +204,7 @@ QDeclarativeCustomParserProperty::~QDeclarativeCustomParserProperty()
delete d; d = 0;
}

QByteArray QDeclarativeCustomParserProperty::name() const
QString QDeclarativeCustomParserProperty::name() const
{
return d->name;
}
Expand Down Expand Up @@ -292,7 +292,7 @@ int QDeclarativeCustomParser::evaluateEnum(const QByteArray& script) const
Resolves \a name to a type, or 0 if it is not a type. This can be used
to type-check object nodes.
*/
const QMetaObject *QDeclarativeCustomParser::resolveType(const QByteArray& name) const
const QMetaObject *QDeclarativeCustomParser::resolveType(const QString& name) const
{
return compiler->resolveType(name);
}
Expand All @@ -302,7 +302,7 @@ const QMetaObject *QDeclarativeCustomParser::resolveType(const QByteArray& name)
used to construct the binding later. \a name
is used as the name of the rewritten function.
*/
QDeclarativeBinding::Identifier QDeclarativeCustomParser::rewriteBinding(const QString& expression, const QByteArray& name)
QDeclarativeBinding::Identifier QDeclarativeCustomParser::rewriteBinding(const QString& expression, const QString& name)
{
return compiler->rewriteBinding(expression, name);
}
Expand Down
8 changes: 4 additions & 4 deletions src/declarative/qml/qdeclarativecustomparser_p.h
Expand Up @@ -78,7 +78,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeCustomParserProperty
QDeclarativeCustomParserProperty &operator=(const QDeclarativeCustomParserProperty &);
~QDeclarativeCustomParserProperty();

QByteArray name() const;
QString name() const;
QDeclarativeScript::Location location() const;

bool isList() const;
Expand All @@ -101,7 +101,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeCustomParserNode
QDeclarativeCustomParserNode &operator=(const QDeclarativeCustomParserNode &);
~QDeclarativeCustomParserNode();

QByteArray name() const;
QString name() const;
QDeclarativeScript::Location location() const;

QList<QDeclarativeCustomParserProperty> properties() const;
Expand Down Expand Up @@ -140,9 +140,9 @@ class Q_DECLARATIVE_EXPORT QDeclarativeCustomParser

int evaluateEnum(const QByteArray&) const;

const QMetaObject *resolveType(const QByteArray&) const;
const QMetaObject *resolveType(const QString&) const;

QDeclarativeBinding::Identifier rewriteBinding(const QString&, const QByteArray&);
QDeclarativeBinding::Identifier rewriteBinding(const QString&, const QString&);

private:
QList<QDeclarativeError> exceptions;
Expand Down
4 changes: 2 additions & 2 deletions src/declarative/qml/qdeclarativecustomparser_p_p.h
Expand Up @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE
class QDeclarativeCustomParserNodePrivate
{
public:
QByteArray name;
QString name;
QList<QDeclarativeCustomParserProperty> properties;
QDeclarativeScript::Location location;

Expand All @@ -78,7 +78,7 @@ class QDeclarativeCustomParserPropertyPrivate
QDeclarativeCustomParserPropertyPrivate()
: isList(false) {}

QByteArray name;
QString name;
bool isList;
QDeclarativeScript::Location location;
QList<QVariant> values;
Expand Down
6 changes: 3 additions & 3 deletions src/declarative/qml/qdeclarativedirparser.cpp
Expand Up @@ -186,7 +186,7 @@ bool QDeclarativeDirParser::parse()
QString::fromUtf8("internal types require 2 arguments, but %1 were provided").arg(sectionCount - 1));
continue;
}
Component entry(sections[1].toUtf8(), sections[2], -1, -1);
Component entry(sections[1], sections[2], -1, -1);
entry.internal = true;
_components.append(entry);
} else if (sections[0] == QLatin1String("typeinfo")) {
Expand All @@ -202,7 +202,7 @@ bool QDeclarativeDirParser::parse()

} else if (sectionCount == 2) {
// No version specified (should only be used for relative qmldir files)
const Component entry(sections[0].toUtf8(), sections[1], -1, -1);
const Component entry(sections[0], sections[1], -1, -1);
_components.append(entry);
} else if (sectionCount == 3) {
const QString &version = sections[1];
Expand All @@ -220,7 +220,7 @@ bool QDeclarativeDirParser::parse()
const int minorVersion = version.mid(dotIndex + 1).toInt(&validVersionNumber);

if (validVersionNumber) {
const Component entry(sections[0].toUtf8(), sections[2], majorVersion, minorVersion);
const Component entry(sections[0], sections[2], majorVersion, minorVersion);

_components.append(entry);
}
Expand Down
4 changes: 2 additions & 2 deletions src/declarative/qml/qdeclarativedirparser_p.h
Expand Up @@ -98,11 +98,11 @@ class QDeclarativeDirParser
Component()
: majorVersion(0), minorVersion(0), internal(false) {}

Component(const QByteArray &typeName, const QString &fileName, int majorVersion, int minorVersion)
Component(const QString &typeName, const QString &fileName, int majorVersion, int minorVersion)
: typeName(typeName), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion),
internal(false) {}

QByteArray typeName;
QString typeName;
QString fileName;
int majorVersion;
int minorVersion;
Expand Down
4 changes: 2 additions & 2 deletions src/declarative/qml/qdeclarativeengine.cpp
Expand Up @@ -952,7 +952,7 @@ Q_AUTOTEST_EXPORT void qmlExecuteDeferred(QObject *object)
if (QDeclarativeDebugService::isDebuggingEnabled()) {
QDeclarativeDebugTrace::startRange(QDeclarativeDebugTrace::Creating);
QDeclarativeType *type = QDeclarativeMetaType::qmlType(object->metaObject());
QString typeName = type ? QLatin1String(type->qmlTypeName()) : QString::fromLatin1(object->metaObject()->className());
QString typeName = type ? type->qmlTypeName() : QString::fromUtf8(object->metaObject()->className());
QDeclarativeDebugTrace::rangeData(QDeclarativeDebugTrace::Creating, typeName);
if (data->outerContext)
QDeclarativeDebugTrace::rangeLocation(QDeclarativeDebugTrace::Creating, data->outerContext->url, data->lineNumber);
Expand Down Expand Up @@ -1580,7 +1580,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeTy
if (overloadError) {
if (hasCopied) raw->release();

error.setDescription(QLatin1String("Type ") + QString::fromUtf8(type->qmlTypeName()) + QLatin1String(" ") + QString::number(type->majorVersion()) + QLatin1String(".") + QString::number(minorVersion) + QLatin1String(" contains an illegal property \"") + overloadName + QLatin1String("\". This is an error in the type's implementation."));
error.setDescription(QLatin1String("Type ") + type->qmlTypeName() + QLatin1String(" ") + QString::number(type->majorVersion()) + QLatin1String(".") + QString::number(minorVersion) + QLatin1String(" contains an illegal property \"") + overloadName + QLatin1String("\". This is an error in the type's implementation."));
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativeexpression_p.h
Expand Up @@ -222,7 +222,7 @@ class QDeclarativeExpressionPrivate : public QObjectPrivate, public QDeclarative

QString url; // This is a QString for a reason. QUrls are slooooooow...
int line;
QByteArray name; //function name, hint for the debugger
QString name; //function name, hint for the debugger

QDeclarativeRefCount *dataRef;
};
Expand Down
4 changes: 2 additions & 2 deletions src/declarative/qml/qdeclarativeinfo.cpp
Expand Up @@ -120,7 +120,7 @@ QDeclarativeInfo::~QDeclarativeInfo()
QString typeName;
QDeclarativeType *type = QDeclarativeMetaType::qmlType(object->metaObject());
if (type) {
typeName = QLatin1String(type->qmlTypeName());
typeName = type->qmlTypeName();
int lastSlash = typeName.lastIndexOf(QLatin1Char('/'));
if (lastSlash != -1)
typeName = typeName.mid(lastSlash+1);
Expand All @@ -136,7 +136,7 @@ QDeclarativeInfo::~QDeclarativeInfo()
typeName += QLatin1Char('*');
type = QDeclarativeMetaType::qmlType(QMetaType::type(typeName.toLatin1()));
if (type) {
typeName = QLatin1String(type->qmlTypeName());
typeName = type->qmlTypeName();
int lastSlash = typeName.lastIndexOf(QLatin1Char('/'));
if (lastSlash != -1)
typeName = typeName.mid(lastSlash+1);
Expand Down
20 changes: 10 additions & 10 deletions src/declarative/qml/qdeclarativemetatype.cpp
Expand Up @@ -180,7 +180,7 @@ class QDeclarativeTypePrivate
bool m_isInterface : 1;
const char *m_iid;
QString m_module;
QByteArray m_name;
QString m_name;
QString m_elementName;
int m_version_maj;
int m_version_min;
Expand Down Expand Up @@ -242,9 +242,9 @@ QDeclarativeType::QDeclarativeType(int index, const QDeclarativePrivate::Registe
QDeclarativeType::QDeclarativeType(int index, const QDeclarativePrivate::RegisterType &type)
: d(new QDeclarativeTypePrivate)
{
QByteArray name = type.uri;
if (type.uri) name += '/';
name += type.elementName;
QString name = QString::fromUtf8(type.uri);
if (type.uri) name += QLatin1Char('/');
name += QString::fromUtf8(type.elementName);

d->m_module = QString::fromUtf8(type.uri);
d->m_name = name;
Expand Down Expand Up @@ -517,14 +517,14 @@ QByteArray QDeclarativeType::typeName() const
const QString &QDeclarativeType::elementName() const
{
if (d->m_elementName.isEmpty()) {
QByteArray n = qmlTypeName();
int idx = n.lastIndexOf('/');
d->m_elementName = QString::fromUtf8(n.mid(idx + 1));
QString n = qmlTypeName();
int idx = n.lastIndexOf(QLatin1Char('/'));
d->m_elementName = n.mid(idx + 1);
}
return d->m_elementName;
}

const QByteArray &QDeclarativeType::qmlTypeName() const
const QString &QDeclarativeType::qmlTypeName() const
{
return d->m_name;
}
Expand Down Expand Up @@ -861,7 +861,7 @@ int registerInterface(const QDeclarativePrivate::RegisterInterface &interface)
data->idToType.insert(type->qListTypeId(), type);
// XXX No insertMulti, so no multi-version interfaces?
if (!type->qmlTypeName().isEmpty())
data->nameToType.insert(QString::fromUtf8(type->qmlTypeName()), type);
data->nameToType.insert(type->qmlTypeName(), type);

if (data->interfaces.size() <= interface.typeId)
data->interfaces.resize(interface.typeId + 16);
Expand Down Expand Up @@ -895,7 +895,7 @@ int registerType(const QDeclarativePrivate::RegisterType &type)
if (dtype->qListTypeId()) data->idToType.insert(dtype->qListTypeId(), dtype);

if (!dtype->qmlTypeName().isEmpty())
data->nameToType.insertMulti(QString::fromUtf8(dtype->qmlTypeName()), dtype);
data->nameToType.insertMulti(dtype->qmlTypeName(), dtype);

data->metaObjectToType.insertMulti(dtype->baseMetaObject(), dtype);

Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativemetatype_p.h
Expand Up @@ -137,7 +137,7 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeType
{
public:
QByteArray typeName() const;
const QByteArray &qmlTypeName() const;
const QString &qmlTypeName() const;
const QString &elementName() const;

QString module() const;
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativescript.cpp
Expand Up @@ -736,7 +736,7 @@ ProcessAST::defineObjectBinding(AST::UiQualifiedId *propertyName,

// XXX this doesn't do anything (_scope never builds up)
_scope.append(resolvableObjectType);
obj->typeName = qualifiedNameId().toUtf8();
obj->typeName = qualifiedNameId();
_scope.removeLast();

obj->location = location;
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativescript_p.h
Expand Up @@ -309,7 +309,7 @@ class Object : public QDeclarativePool::Class
int type;

// The fully-qualified name of this type
QByteArray typeName;
QString typeName;
// The id assigned to the object (if any). Set by the QDeclarativeCompiler
QString id;
// The id index assigned to the object (if any). Set by the QDeclarativeCompiler
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativevme.cpp
Expand Up @@ -793,7 +793,7 @@ QObject *QDeclarativeVME::run(QList<QDeclarativeError> *errors,
QDeclarativeExpression *expr =
new QDeclarativeExpression(CTXT, context, PRIMITIVES.at(instr.value));
expr->setSourceLocation(COMP->name, instr.line);
static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr))->name = DATAS.at(instr.name);
static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr))->name = QString::fromUtf8(DATAS.at(instr.name));
bs->setExpression(expr);
QML_END_INSTR(StoreSignal)

Expand Down
2 changes: 1 addition & 1 deletion src/declarative/util/qdeclarativeconnections.cpp
Expand Up @@ -202,7 +202,7 @@ QDeclarativeConnectionsParser::compile(const QList<QDeclarativeCustomParserPrope

for(int ii = 0; ii < props.count(); ++ii)
{
QString propName = QString::fromUtf8(props.at(ii).name());
QString propName = props.at(ii).name();
if (!propName.startsWith(QLatin1String("on")) || !propName.at(2).isUpper()) {
error(props.at(ii), QDeclarativeConnections::tr("Cannot assign to non-existent property \"%1\"").arg(propName));
return QByteArray();
Expand Down
8 changes: 4 additions & 4 deletions src/declarative/util/qdeclarativelistmodel.cpp
Expand Up @@ -792,14 +792,14 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser
error(nodeProp, QDeclarativeListModel::tr("ListElement: cannot contain nested elements"));
return false;
}
if (nodeProp.name() == "id") {
if (nodeProp.name() == QStringLiteral("id")) {
error(nodeProp, QDeclarativeListModel::tr("ListElement: cannot use reserved \"id\" property"));
return false;
}

ListInstruction li;
int ref = data.count();
data.append(nodeProp.name());
data.append(nodeProp.name().toUtf8());
data.append('\0');
li.type = ListInstruction::Set;
li.dataIdx = ref;
Expand Down Expand Up @@ -895,12 +895,12 @@ QByteArray QDeclarativeListModelParser::compile(const QList<QDeclarativeCustomPa
{
QList<ListInstruction> instr;
QByteArray data;
listElementTypeName = QByteArray(); // unknown
listElementTypeName = QString(); // unknown

for(int ii = 0; ii < customProps.count(); ++ii) {
const QDeclarativeCustomParserProperty &prop = customProps.at(ii);
if(!prop.name().isEmpty()) { // isn't default property
error(prop, QDeclarativeListModel::tr("ListModel: undefined property '%1'").arg(QString::fromUtf8(prop.name())));
error(prop, QDeclarativeListModel::tr("ListModel: undefined property '%1'").arg(prop.name()));
return QByteArray();
}

Expand Down

0 comments on commit bcc9a4b

Please sign in to comment.