From 9175109e8c6f55c365edf96797c249ffe6b74bf7 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 15 Sep 2011 14:11:55 +0200 Subject: [PATCH] Get rid of QDeclarativeUtils All the QChar methods needed by QtDeclarative have now been optimized to achieve at least as good performance as the QDeclarativeUtils versions. Change-Id: I5b8dd58f9b597f716b53563d07d39d894c5dd666 Reviewed-on: http://codereview.qt-project.org/5059 Reviewed-by: Qt Sanity Bot Reviewed-by: Lars Knoll --- src/declarative/qml/ftw/ftw.pri | 1 - src/declarative/qml/ftw/qdeclarativeutils_p.h | 91 -------------------- src/declarative/qml/parser/qdeclarativejslexer.cpp | 37 ++++---- src/declarative/qml/qdeclarativecompiler.cpp | 19 ++-- src/declarative/qml/qdeclarativedirparser.cpp | 7 +- src/declarative/qml/v4/qdeclarativev4irbuilder.cpp | 3 +- 6 files changed, 31 insertions(+), 127 deletions(-) delete mode 100644 src/declarative/qml/ftw/qdeclarativeutils_p.h diff --git a/src/declarative/qml/ftw/ftw.pri b/src/declarative/qml/ftw/ftw.pri index 545c47e..d6e7df5 100644 --- a/src/declarative/qml/ftw/ftw.pri +++ b/src/declarative/qml/ftw/ftw.pri @@ -9,7 +9,6 @@ HEADERS += \ $$PWD/qdeclarativerefcount_p.h \ $$PWD/qdeclarativepool_p.h \ $$PWD/qfieldlist_p.h \ - $$PWD/qdeclarativeutils_p.h \ $$PWD/qfastmetabuilder_p.h \ $$PWD/qhashfield_p.h \ diff --git a/src/declarative/qml/ftw/qdeclarativeutils_p.h b/src/declarative/qml/ftw/qdeclarativeutils_p.h deleted file mode 100644 index ec19d9c..0000000 --- a/src/declarative/qml/ftw/qdeclarativeutils_p.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEUTIL_P_H -#define QDECLARATIVEUTIL_P_H - -#include - -QT_BEGIN_NAMESPACE - -namespace QDeclarativeUtils { - -inline bool isUpper(const QChar &qc) -{ - ushort c = qc.unicode(); - return ((c >= 'A' && c <= 'Z') || (c > 127 && QChar::category(c) == QChar::Letter_Uppercase)); -} - -inline bool isLower(const QChar &qc) -{ - ushort c = qc.unicode(); - return ((c >= 'a' && c <= 'z') || (c > 127 && QChar::category(c) == QChar::Letter_Lowercase)); -} - -inline bool isLetter(const QChar &qc) -{ - ushort c = qc.unicode(); - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c > 127 && qc.isLetter())); -} - -inline bool isDigit(const QChar &qc) -{ - ushort c = qc.unicode(); - return ((c >= '0' && c <= '9') || (c > 127 && qc.isDigit())); -} - -inline bool isLetterOrNumber(const QChar &qc) -{ - ushort c = qc.unicode(); - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c > 127 && qc.isLetterOrNumber())); -} - -inline bool isSpace(const QChar &qc) -{ - ushort c = qc.unicode(); - return (c == 0x20 || (c >= 0x09 && c <= 0x0D) || c == 0x85 || (c > 127 && qc.isSpace())); -} - -} // namespace QDeclarative - -QT_END_NAMESPACE - -#endif // QDECLARATIVEUTIL_P_H diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp index d466140..4535027 100644 --- a/src/declarative/qml/parser/qdeclarativejslexer.cpp +++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp @@ -43,7 +43,6 @@ #include "qdeclarativejsengine_p.h" #include "qdeclarativejsmemorypool_p.h" -#include #include #include #include @@ -279,7 +278,7 @@ again: _validTokenText = false; _tokenLinePtr = _lastLinePtr; - while (QDeclarativeUtils::isSpace(_char)) { + while (_char.isSpace()) { if (_char == QLatin1Char('\n')) { _tokenLinePtr = _codePtr; @@ -418,19 +417,19 @@ again: return T_DIVIDE_; case '.': - if (QDeclarativeUtils::isDigit(_char)) { + if (_char.isDigit()) { QVarLengthArray chars; chars.append(ch.unicode()); // append the `.' - while (QDeclarativeUtils::isDigit(_char)) { + while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { - if (QDeclarativeUtils::isDigit(_codePtr[0]) || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && - QDeclarativeUtils::isDigit(_codePtr[1]))) { + if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && + _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' @@ -440,7 +439,7 @@ again: scanChar(); // consume the sign } - while (QDeclarativeUtils::isDigit(_char)) { + while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } @@ -667,7 +666,7 @@ again: } default: - if (QDeclarativeUtils::isLetter(ch) || ch == QLatin1Char('$') || ch == QLatin1Char('_') || (ch == QLatin1Char('\\') && _char == QLatin1Char('u'))) { + if (ch.isLetter() || ch == QLatin1Char('$') || ch == QLatin1Char('_') || (ch == QLatin1Char('\\') && _char == QLatin1Char('u'))) { bool identifierWithEscapeChars = false; if (ch == QLatin1Char('\\')) { identifierWithEscapeChars = true; @@ -682,7 +681,7 @@ again: } } while (true) { - if (QDeclarativeUtils::isLetterOrNumber(_char) || _char == QLatin1Char('$') || _char == QLatin1Char('_')) { + if (_char.isLetterOrNumber() || _char == QLatin1Char('$') || _char == QLatin1Char('_')) { if (identifierWithEscapeChars) _tokenText += _char; @@ -721,13 +720,13 @@ again: return kind; } } - } else if (QDeclarativeUtils::isDigit(ch)) { + } else if (ch.isDigit()) { if (ch != QLatin1Char('0')) { double integer = ch.unicode() - '0'; QChar n = _char; const QChar *code = _codePtr; - while (QDeclarativeUtils::isDigit(n)) { + while (n.isDigit()) { integer = integer * 10 + (n.unicode() - '0'); n = *code++; } @@ -761,7 +760,7 @@ again: } // decimal integer literal - while (QDeclarativeUtils::isDigit(_char)) { + while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); // consume the digit } @@ -770,14 +769,14 @@ again: chars.append(_char.unicode()); scanChar(); // consume `.' - while (QDeclarativeUtils::isDigit(_char)) { + while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { - if (QDeclarativeUtils::isDigit(_codePtr[0]) || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && - QDeclarativeUtils::isDigit(_codePtr[1]))) { + if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && + _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' @@ -787,15 +786,15 @@ again: scanChar(); // consume the sign } - while (QDeclarativeUtils::isDigit(_char)) { + while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } } } } else if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { - if (QDeclarativeUtils::isDigit(_codePtr[0]) || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && - QDeclarativeUtils::isDigit(_codePtr[1]))) { + if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && + _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' @@ -805,7 +804,7 @@ again: scanChar(); // consume the sign } - while (QDeclarativeUtils::isDigit(_char)) { + while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); } diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index b3d714d..b6c1f47 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -62,7 +62,6 @@ #include "private/qdeclarativeglobal_p.h" #include "private/qdeclarativebinding_p.h" #include "private/qdeclarativev4compiler_p.h" -#include "private/qdeclarativeutils_p.h" #include #include @@ -127,7 +126,7 @@ bool QDeclarativeCompiler::isAttachedPropertyName(const QString &name) bool QDeclarativeCompiler::isAttachedPropertyName(const QHashedStringRef &name) { - return !name.isEmpty() && QDeclarativeUtils::isUpper(name.at(0)); + return !name.isEmpty() && name.at(0).isUpper(); } /*! @@ -154,7 +153,7 @@ bool QDeclarativeCompiler::isSignalPropertyName(const QHashedStringRef &name) for (int i = 2; i < ns; ++i) { const QChar curr = name.at(i); if (curr.unicode() == '_') continue; - if (QDeclarativeUtils::isUpper(curr)) return true; + if (curr.isUpper()) return true; return false; } return false; // consists solely of underscores - invalid. @@ -1463,7 +1462,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeScript::Property *prop, QDecl // Note that the property name could start with any alpha or '_' or '$' character, // so we need to do the lower-casing of the first alpha character. for (int firstAlphaIndex = 0; firstAlphaIndex < name.size(); ++firstAlphaIndex) { - if (QDeclarativeUtils::isUpper(name.at(firstAlphaIndex))) { + if (name.at(firstAlphaIndex).isUpper()) { name[firstAlphaIndex] = name.at(firstAlphaIndex).toLower(); break; } @@ -2310,7 +2309,7 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop COMPILE_EXCEPTION(v, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name()))); QString string = v->value.asString(); - if (!QDeclarativeUtils::isUpper(string.at(0))) + if (!string.at(0).isUpper()) return true; QStringList parts = string.split(QLatin1Char('.')); @@ -2443,7 +2442,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeScript::Object *obj) } } - if (QDeclarativeUtils::isUpper(prop.name.at(0))) + if (prop.name.at(0).isUpper()) COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter")); if (enginePrivate->v8engine()->illegalNames().contains(prop.name)) @@ -2574,7 +2573,7 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeScript::Object *obj, Dyn int lastSlash = path.lastIndexOf(QLatin1Char('/')); if (lastSlash > -1) { QString nameBase = path.mid(lastSlash + 1, path.length()-lastSlash-5); - if (!nameBase.isEmpty() && QDeclarativeUtils::isUpper(nameBase.at(0))) + if (!nameBase.isEmpty() && nameBase.at(0).isUpper()) newClassName = nameBase.toUtf8() + "_QMLTYPE_" + QByteArray::number(uniqueClassId); } } @@ -2891,16 +2890,16 @@ bool QDeclarativeCompiler::checkValidId(QDeclarativeScript::Value *v, const QStr COMPILE_EXCEPTION(v, tr( "Invalid empty ID")); QChar ch = val.at(0); - if (QDeclarativeUtils::isLetter(ch) && !QDeclarativeUtils::isLower(ch)) + if (ch.isLetter() && !ch.isLower()) COMPILE_EXCEPTION(v, tr( "IDs cannot start with an uppercase letter")); QChar u(QLatin1Char('_')); - if (!QDeclarativeUtils::isLetter(ch) && ch != u) + if (!ch.isLetter() && ch != u) COMPILE_EXCEPTION(v, tr( "IDs must start with a letter or underscore")); for (int ii = 1; ii < val.count(); ++ii) { ch = val.at(ii); - if (!QDeclarativeUtils::isLetterOrNumber(ch) && ch != u) + if (!ch.isLetterOrNumber() && ch != u) COMPILE_EXCEPTION(v, tr( "IDs must contain only letters, numbers, and underscores")); } diff --git a/src/declarative/qml/qdeclarativedirparser.cpp b/src/declarative/qml/qdeclarativedirparser.cpp index 49cb40f..69c323b 100644 --- a/src/declarative/qml/qdeclarativedirparser.cpp +++ b/src/declarative/qml/qdeclarativedirparser.cpp @@ -42,7 +42,6 @@ #include "private/qdeclarativedirparser_p.h" #include "qdeclarativeerror.h" #include -#include #include #include @@ -141,9 +140,9 @@ bool QDeclarativeDirParser::parse() while (index != length) { const QChar ch = line.at(index); - if (QDeclarativeUtils::isSpace(ch)) { + if (ch.isSpace()) { do { ++index; } - while (index != length && QDeclarativeUtils::isSpace(line.at(index))); + while (index != length && line.at(index).isSpace()); } else if (ch == QLatin1Char('#')) { // recognized a comment @@ -153,7 +152,7 @@ bool QDeclarativeDirParser::parse() const int start = index; do { ++index; } - while (index != length && !QDeclarativeUtils::isSpace(line.at(index))); + while (index != length && !line.at(index).isSpace()); const QString lexeme = line.mid(start, index - start); diff --git a/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp b/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp index 9237a3e..51afe75 100644 --- a/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp +++ b/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp @@ -44,7 +44,6 @@ #include // For AnchorLine #include -#include DEFINE_BOOL_CONFIG_OPTION(qmlVerboseCompiler, QML_VERBOSE_COMPILER) @@ -583,7 +582,7 @@ bool QDeclarativeV4IRBuilder::visit(AST::FieldMemberExpression *ast) break; case IR::Name::AttachType: - if (QDeclarativeUtils::isUpper(name.at(0))) { + if (name.at(0).isUpper()) { QByteArray utf8Name = name.toUtf8(); const char *enumName = utf8Name.constData(); -- 1.7.2.5