From 6aa14b5d01d86894f620be2adce75e069b1a1e48 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 21 May 2013 22:04:36 +0200 Subject: Remove v8 dependencies in qhashedstring Also remove now unused API in v8::String Change-Id: I2570aedf407c89ad85da01cf0e2153a52b4e562d Reviewed-by: Simon Hausmann --- src/qml/qml/ftw/qhashedstring.cpp | 10 +--- src/qml/qml/ftw/qhashedstring_p.h | 105 +++++++++++++++------------------ src/qml/qml/qqmlintegercache_p.h | 4 +- src/qml/qml/qqmlmetatype.cpp | 6 +- src/qml/qml/qqmlmetatype_p.h | 8 +-- src/qml/qml/qqmlpropertycache.cpp | 8 +-- src/qml/qml/qqmlpropertycache_p.h | 2 +- src/qml/qml/qqmltypenamecache.cpp | 4 +- src/qml/qml/qqmltypenamecache_p.h | 4 +- src/qml/qml/v4/qcalculatehash_p.h | 73 ----------------------- src/qml/qml/v4/qv4string_p.h | 4 ++ src/qml/qml/v4/qv4v8.cpp | 59 ------------------ src/qml/qml/v4/qv4v8_p.h | 84 +------------------------- src/qml/qml/v4/v4.pri | 1 - src/qml/qml/v8/qv8contextwrapper.cpp | 6 +- src/qml/qml/v8/qv8engine_p.h | 11 ---- src/qml/qml/v8/qv8qobjectwrapper.cpp | 18 +++--- src/qml/qml/v8/qv8qobjectwrapper_p.h | 16 ++--- src/qml/qml/v8/qv8typewrapper.cpp | 8 +-- src/qml/qml/v8/qv8valuetypewrapper.cpp | 4 +- src/qml/qml/v8/qv8valuetypewrapper_p.h | 2 +- src/qml/types/qqmllistmodel.cpp | 20 ++----- 22 files changed, 109 insertions(+), 348 deletions(-) delete mode 100644 src/qml/qml/v4/qcalculatehash_p.h (limited to 'src/qml') diff --git a/src/qml/qml/ftw/qhashedstring.cpp b/src/qml/qml/ftw/qhashedstring.cpp index 8f6c57e029..577757f3c0 100644 --- a/src/qml/qml/ftw/qhashedstring.cpp +++ b/src/qml/qml/ftw/qhashedstring.cpp @@ -40,20 +40,16 @@ ****************************************************************************/ #include "qhashedstring_p.h" -#include inline quint32 stringHash(const QChar* data, int length) { - quint32 rv = calculateHash((quint16*)data, length); - Q_ASSERT(rv == v8::String::ComputeHash((uint16_t*)data, length)); - return rv; + return QV4::String::createHashValue(data, length); } inline quint32 stringHash(const char *data, int length) { - quint32 rv = calculateHash((quint8*)data, length); - Q_ASSERT(rv == v8::String::ComputeHash((char *)data, length)); - return rv; + QString s = QString::fromLatin1(data, length); + return QV4::String::createHashValue(s.constData(), s.length()); } void QHashedString::computeHash() const diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index 9393e1fed0..1198b0244f 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -55,8 +55,8 @@ #include #include -#include #include +#include #include @@ -85,8 +85,6 @@ public: inline quint32 hash() const; inline quint32 existingHash() const; - static inline bool isUpper(const QChar &); - static bool compare(const QChar *lhs, const QChar *rhs, int length); static inline bool compare(const QChar *lhs, const char *rhs, int length); static inline bool compare(const char *lhs, const char *rhs, int length); @@ -98,27 +96,26 @@ private: mutable quint32 m_hash; }; -class Q_AUTOTEST_EXPORT QHashedV8String +class Q_AUTOTEST_EXPORT QHashedV4String { public: - inline QHashedV8String(); - explicit inline QHashedV8String(v8::Handle); - inline QHashedV8String(const QHashedV8String &string); - inline QHashedV8String &operator=(const QHashedV8String &other); + inline QHashedV4String(); + explicit inline QHashedV4String(const QV4::Value &s); + inline QHashedV4String(const QHashedV4String &string); + inline QHashedV4String &operator=(const QHashedV4String &other); - inline bool operator==(const QHashedV8String &string); + inline bool operator==(const QHashedV4String &string); inline quint32 hash() const; inline int length() const; inline quint32 symbolId() const; - inline v8::Handle string() const; + inline QV4::Value string() const; inline QString toString() const; private: - v8::String::CompleteHashData m_hash; - v8::Handle m_string; + QV4::PersistentValue m_string; }; class QHashedCStringRef; @@ -262,19 +259,24 @@ public: inline char *cStrData() const { return (char *)ckey; } inline uint16_t *utf16Data() const { return (uint16_t *)strData->data(); } - inline bool equals(v8::Handle string) const { - v8::Handle data = isQString() ? v8::String::New(utf16Data(), length) - : v8::String::New(cStrData(), length); - return string->Equals(data); + inline bool equals(const QV4::Value &string) const { + QString s = string.toQString(); + if (isQString()) { + QStringDataPtr dd; + dd.ptr = strData; + return QString(dd) == s; + } else { + return QLatin1String(cStrData(), length) == s; + } } - inline bool symbolEquals(const QHashedV8String &string) const { + inline bool symbolEquals(const QHashedV4String &string) const { Q_ASSERT(string.symbolId() != 0); return length == string.length() && hash == string.hash() && (string.symbolId() == symbolId || equals(string.string())); } - inline bool equals(const QHashedV8String &string) const { + inline bool equals(const QHashedV4String &string) const { return length == string.length() && hash == string.hash() && equals(string.string()); } @@ -333,7 +335,7 @@ struct HashedForm {}; template<> struct HashedForm { typedef QHashedString Type; }; template<> struct HashedForm { typedef QHashedStringRef Type; }; template<> struct HashedForm { typedef const QHashedString &Type; }; -template<> struct HashedForm { typedef const QHashedV8String &Type; }; +template<> struct HashedForm { typedef const QHashedV4String &Type; }; template<> struct HashedForm { typedef const QHashedStringRef &Type; }; template<> struct HashedForm { typedef QHashedCStringRef Type; }; template<> struct HashedForm { typedef const QHashedCStringRef &Type; }; @@ -344,7 +346,7 @@ public: static HashedForm::Type hashedString(const QString &s) { return QHashedString(s);} static HashedForm::Type hashedString(const QStringRef &s) { return QHashedStringRef(s.constData(), s.size());} static HashedForm::Type hashedString(const QHashedString &s) { return s; } - static HashedForm::Type hashedString(const QHashedV8String &s) { return s; } + static HashedForm::Type hashedString(const QHashedV4String &s) { return s; } static HashedForm::Type hashedString(const QHashedStringRef &s) { return s; } static HashedForm::Type hashedString(const QLatin1String &s) { return QHashedCStringRef(s.data(), s.size()); } @@ -352,14 +354,14 @@ public: static const QString &toQString(const QString &s) { return s; } static const QString &toQString(const QHashedString &s) { return s; } - static QString toQString(const QHashedV8String &s) { return s.toString(); } + static QString toQString(const QHashedV4String &s) { return s.toString(); } static QString toQString(const QHashedStringRef &s) { return s.toString(); } static QString toQString(const QLatin1String &s) { return QString(s); } static QString toQString(const QHashedCStringRef &s) { return s.toUtf16(); } static inline quint32 hashOf(const QHashedStringRef &s) { return s.hash(); } - static inline quint32 hashOf(const QHashedV8String &s) { return s.hash(); } + static inline quint32 hashOf(const QHashedV4String &s) { return s.hash(); } template static inline quint32 hashOf(const K &key) { return hashedString(key).hash(); } @@ -402,7 +404,7 @@ public: template inline Node *findNode(const K &) const; - inline Node *findSymbolNode(const QHashedV8String &) const; + inline Node *findSymbolNode(const QHashedV4String &) const; inline Node *createNode(const Node &o); @@ -473,7 +475,7 @@ public: template inline T *value(const K &) const; - inline T *value(const QHashedV8String &string) const; + inline T *value(const QHashedV4String &string) const; inline T *value(const ConstIterator &) const; template @@ -867,7 +869,7 @@ typename QStringHash::Node *QStringHash::findNode(const K &key) const } template -typename QStringHash::Node *QStringHash::findSymbolNode(const QHashedV8String &string) const +typename QStringHash::Node *QStringHash::findSymbolNode(const QHashedV4String &string) const { Q_ASSERT(string.symbolId() != 0); @@ -897,7 +899,7 @@ T *QStringHash::value(const ConstIterator &iter) const } template -T *QStringHash::value(const QHashedV8String &string) const +T *QStringHash::value(const QHashedV4String &string) const { Node *n = string.symbolId()?findSymbolNode(string):findNode(string); return n?&n->value:0; @@ -1123,66 +1125,55 @@ quint32 QHashedString::existingHash() const return m_hash; } -bool QHashedString::isUpper(const QChar &qc) -{ - ushort c = qc.unicode(); - // Optimize for _, a-z and A-Z. - return ((c != '_' ) && (!(c >= 'a' && c <= 'z')) && - ((c >= 'A' && c <= 'Z') || QChar::category(c) == QChar::Letter_Uppercase)); -} - -QHashedV8String::QHashedV8String() +QHashedV4String::QHashedV4String() { } -QHashedV8String::QHashedV8String(v8::Handle string) -: m_hash(string->CompleteHash()), m_string(string) +QHashedV4String::QHashedV4String(const QV4::Value &s) + : m_string(s) { - Q_ASSERT(!m_string.IsEmpty()); + Q_ASSERT(!s.toQString().isEmpty()); } -QHashedV8String::QHashedV8String(const QHashedV8String &string) -: m_hash(string.m_hash), m_string(string.m_string) +QHashedV4String::QHashedV4String(const QHashedV4String &string) + : m_string(string.m_string) { } -QHashedV8String &QHashedV8String::operator=(const QHashedV8String &other) +QHashedV4String &QHashedV4String::operator=(const QHashedV4String &other) { - m_hash = other.m_hash; m_string = other.m_string; return *this; } -bool QHashedV8String::operator==(const QHashedV8String &string) +bool QHashedV4String::operator==(const QHashedV4String &string) { - return m_hash.hash == string.m_hash.hash && m_hash.length == string.m_hash.length && - m_string.IsEmpty() == m_string.IsEmpty() && - (m_string.IsEmpty() || m_string->StrictEquals(string.m_string)); + return m_string.value().asString()->isEqualTo(string.m_string.value().asString()); } -quint32 QHashedV8String::hash() const +quint32 QHashedV4String::hash() const { - return m_hash.hash; + return m_string.value().asString()->hashValue(); } -int QHashedV8String::length() const +int QHashedV4String::length() const { - return m_hash.length; + return m_string.value().asString()->toQString().length(); } -quint32 QHashedV8String::symbolId() const +quint32 QHashedV4String::symbolId() const { - return m_hash.symbol_id; + return m_string.value().asString()->identifier; } -v8::Handle QHashedV8String::string() const +QV4::Value QHashedV4String::string() const { - return m_string; + return m_string.value(); } -QString QHashedV8String::toString() const +QString QHashedV4String::toString() const { - return m_string->v4Value().toQString(); + return m_string.value().toQString(); } QHashedStringRef::QHashedStringRef() @@ -1327,7 +1318,7 @@ bool QHashedStringRef::isLatin1() const bool QHashedStringRef::startsWithUpper() const { if (m_length < 1) return false; - return QHashedString::isUpper(m_data[0]); + return m_data[0].isUpper(); } quint32 QHashedStringRef::hash() const diff --git a/src/qml/qml/qqmlintegercache_p.h b/src/qml/qml/qqmlintegercache_p.h index 8b2f97267e..5fe4039f3c 100644 --- a/src/qml/qml/qqmlintegercache_p.h +++ b/src/qml/qml/qqmlintegercache_p.h @@ -71,7 +71,7 @@ public: void reserve(int); int value(const QString &); - inline int value(const QHashedV8String &); + inline int value(const QHashedV4String &); QString findId(int value) const; @@ -80,7 +80,7 @@ private: StringCache stringCache; }; -int QQmlIntegerCache::value(const QHashedV8String &name) +int QQmlIntegerCache::value(const QHashedV4String &name) { int *result = stringCache.value(name); return result?*result:-1; diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 372475d85c..c616d5c33e 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -917,7 +917,7 @@ int QQmlType::enumValue(const QHashedCStringRef &name, bool *ok) const return -1; } -int QQmlType::enumValue(const QHashedV8String &name, bool *ok) const +int QQmlType::enumValue(const QHashedV4String &name, bool *ok) const { Q_ASSERT(ok); *ok = true; @@ -991,7 +991,7 @@ QQmlType *QQmlTypeModule::type(const QHashedStringRef &name, int minor) return 0; } -QQmlType *QQmlTypeModule::type(const QHashedV8String &name, int minor) +QQmlType *QQmlTypeModule::type(const QHashedV4String &name, int minor) { QReadLocker lock(metaTypeDataLock()); @@ -1060,7 +1060,7 @@ QQmlType *QQmlTypeModuleVersion::type(const QHashedStringRef &name) const else return 0; } -QQmlType *QQmlTypeModuleVersion::type(const QHashedV8String &name) const +QQmlType *QQmlTypeModuleVersion::type(const QHashedV4String &name) const { if (m_module) return m_module->type(name, m_minor); else return 0; diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h index 497afffb5d..5f3d115d5f 100644 --- a/src/qml/qml/qqmlmetatype_p.h +++ b/src/qml/qml/qqmlmetatype_p.h @@ -136,7 +136,7 @@ private: struct QQmlMetaTypeData; class QHashedCStringRef; -class QHashedV8String; +class QHashedV4String; class Q_QML_PRIVATE_EXPORT QQmlType { public: @@ -213,7 +213,7 @@ public: int enumValue(const QHashedStringRef &, bool *ok) const; int enumValue(const QHashedCStringRef &, bool *ok) const; - int enumValue(const QHashedV8String &, bool *ok) const; + int enumValue(const QHashedV4String &, bool *ok) const; private: QQmlType *superType() const; friend class QQmlTypePrivate; @@ -251,7 +251,7 @@ public: int maximumMinorVersion() const; QQmlType *type(const QHashedStringRef &, int); - QQmlType *type(const QHashedV8String &, int); + QQmlType *type(const QHashedV4String &, int); QList singletonTypes(int) const; @@ -277,7 +277,7 @@ public: int minorVersion() const; QQmlType *type(const QHashedStringRef &) const; - QQmlType *type(const QHashedV8String &) const; + QQmlType *type(const QHashedV4String &) const; private: QQmlTypeModule *m_module; diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 55ecdff14e..4adb268fb4 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -1366,9 +1366,9 @@ inline const QString &qQmlPropertyCacheToString(const QString &string) return string; } -inline QString qQmlPropertyCacheToString(const QHashedV8String &string) +inline QString qQmlPropertyCacheToString(const QHashedV4String &string) { - return string.string()->v4Value().toQString(); + return string.toString(); } template @@ -1406,10 +1406,10 @@ qQmlPropertyCacheProperty(QQmlEngine *engine, QObject *obj, const T &name, } QQmlPropertyData * -QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj, const QHashedV8String &name, +QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj, const QHashedV4String &name, QQmlContextData *context, QQmlPropertyData &local) { - return qQmlPropertyCacheProperty(engine, obj, name, context, local); + return qQmlPropertyCacheProperty(engine, obj, name, context, local); } QQmlPropertyData * diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index 4f608e1d56..15bd83fcb3 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -304,7 +304,7 @@ public: inline QQmlEngine *qmlEngine() const; static QQmlPropertyData *property(QQmlEngine *, QObject *, const QString &, QQmlContextData *, QQmlPropertyData &); - static QQmlPropertyData *property(QQmlEngine *, QObject *, const QHashedV8String &, + static QQmlPropertyData *property(QQmlEngine *, QObject *, const QHashedV4String &, QQmlContextData *, QQmlPropertyData &); static int *methodParameterTypes(QObject *, int index, QVarLengthArray &dummy, QByteArray *unknownTypeError); diff --git a/src/qml/qml/qqmltypenamecache.cpp b/src/qml/qml/qqmltypenamecache.cpp index 180c620558..8c522c2ffa 100644 --- a/src/qml/qml/qqmltypenamecache.cpp +++ b/src/qml/qml/qqmltypenamecache.cpp @@ -91,7 +91,7 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name, return typeSearch(i->modules, name); } -QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedV8String &name) +QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedV4String &name) { Result result = query(m_namedImports, name); @@ -101,7 +101,7 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedV8String &name) return result; } -QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedV8String &name, const void *importNamespace) +QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedV4String &name, const void *importNamespace) { Q_ASSERT(importNamespace); const Import *i = static_cast(importNamespace); diff --git a/src/qml/qml/qqmltypenamecache_p.h b/src/qml/qml/qqmltypenamecache_p.h index 4484adffc6..33c01211ed 100644 --- a/src/qml/qml/qqmltypenamecache_p.h +++ b/src/qml/qml/qqmltypenamecache_p.h @@ -90,8 +90,8 @@ public: }; Result query(const QHashedStringRef &); Result query(const QHashedStringRef &, const void *importNamespace); - Result query(const QHashedV8String &); - Result query(const QHashedV8String &, const void *importNamespace); + Result query(const QHashedV4String &); + Result query(const QHashedV4String &, const void *importNamespace); private: friend class QQmlImports; diff --git a/src/qml/qml/v4/qcalculatehash_p.h b/src/qml/qml/v4/qcalculatehash_p.h deleted file mode 100644 index 8cccc5d0d1..0000000000 --- a/src/qml/qml/v4/qcalculatehash_p.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtV8 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, 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, Digia gives you certain additional -** rights. These rights are described in the Digia 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. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CALCULATEHASH_P_H -#define CALCULATEHASH_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include "qv4v8_p.h" -QT_BEGIN_NAMESPACE - -inline uint32_t calculateHash(const quint8* chars, int length) -{ - return v8::String::ComputeHash((char *)chars, length); -} - -inline uint32_t calculateHash(const quint16* chars, int length) -{ - return v8::String::ComputeHash((uint16_t *)chars, length); -} - -QT_END_NAMESPACE - -#endif // CALCULATEHASH_P_H diff --git a/src/qml/qml/v4/qv4string_p.h b/src/qml/qml/v4/qv4string_p.h index 9db709a753..e33c4d81e9 100644 --- a/src/qml/qml/v4/qv4string_p.h +++ b/src/qml/qml/v4/qv4string_p.h @@ -110,6 +110,10 @@ struct String : public Managed { void createHashValue() const; static uint createHashValue(const QChar *ch, int length); + bool startsWithUpper() const { + return _text.length() && _text.at(0).isUpper(); + } + QString _text; mutable uint stringHash; mutable uint identifier; diff --git a/src/qml/qml/v4/qv4v8.cpp b/src/qml/qml/v4/qv4v8.cpp index 9902528a04..ba9509e499 100644 --- a/src/qml/qml/v4/qv4v8.cpp +++ b/src/qml/qml/v4/qv4v8.cpp @@ -508,58 +508,6 @@ Handle Value::fromV4Value(const QV4::Value &v4Value) } -int String::Length() const -{ - return asV4String()->toQString().length(); -} - -uint32_t String::Hash() const -{ - return asV4String()->hashValue(); -} - - -String::CompleteHashData String::CompleteHash() const -{ - QV4::String *s = asV4String(); - CompleteHashData data; - data.hash = s->hashValue(); - data.length = s->toQString().length(); - data.symbol_id = s->identifier; - return data; -} - -uint32_t String::ComputeHash(uint16_t *string, int length) -{ - return QV4::String::createHashValue(reinterpret_cast(string), length); -} - -uint32_t String::ComputeHash(char *string, int length) -{ - // ### unefficient - QString s = QString::fromLatin1((char *)string, length); - return QV4::String::createHashValue(s.constData(), s.length()); -} - -bool String::Equals(uint16_t *str, int length) -{ - return asQString() == QString(reinterpret_cast(str), length); -} - -bool String::Equals(char *str, int length) -{ - return asQString() == QString::fromLatin1(str, length); -} - -int String::Write(uint16_t *buffer) const -{ - uint length = asQString().length(); - if (length == 0) - return 0; - memcpy(buffer, asQString().constData(), length*sizeof(QChar)); - return length; -} - String::ExternalStringResource *String::GetExternalStringResource() const { Q_UNIMPLEMENTED(); @@ -584,13 +532,6 @@ Handle String::New(const uint16_t *data, int length) return v; } -Handle String::NewSymbol(const char *data, int length) -{ - QString str = QString::fromLatin1(data, length); - QV4::String *vmString = currentEngine()->newIdentifier(str); - return New(vmString); -} - Handle String::New(QV4::String *s) { return QV4::Value::fromString(s); diff --git a/src/qml/qml/v4/qv4v8_p.h b/src/qml/qml/v4/qv4v8_p.h index b73d26ef62..dcd44d5916 100644 --- a/src/qml/qml/v4/qv4v8_p.h +++ b/src/qml/qml/v4/qv4v8_p.h @@ -799,82 +799,6 @@ class V8EXPORT Value { */ class V8EXPORT String : public Value { public: - /** - * Returns the number of characters in this string. - */ - int Length() const; - - - /** - * Returns the hash of this string. - */ - uint32_t Hash() const; - - struct CompleteHashData { - CompleteHashData() : length(0), hash(0), symbol_id(0) {} - int length; - uint32_t hash; - uint32_t symbol_id; - }; - - /** - * Returns the "complete" hash of the string. This is - * all the information about the string needed to implement - * a very efficient hash keyed on the string. - * - * The members of CompleteHashData are: - * length: The length of the string. Equivalent to Length() - * hash: The hash of the string. Equivalent to Hash() - * symbol_id: If the string is a sequential symbol, the symbol - * id, otherwise 0. If the symbol ids of two strings are - * the same (and non-zero) the two strings are identical. - * If the symbol ids are different the strings may still be - * identical, but an Equals() check must be performed. - */ - CompleteHashData CompleteHash() const; - - /** - * Compute a hash value for the passed UTF16 string - * data. - */ - static uint32_t ComputeHash(uint16_t *string, int length); - static uint32_t ComputeHash(char *string, int length); - - /** - * Returns true if this string is equal to the external - * string data provided. - */ - bool Equals(uint16_t *string, int length); - bool Equals(char *string, int length); - bool Equals(Handle that) const { - return v8::Value::Equals(that); - } - - /** - * Write the contents of the string to an external buffer. - * If no arguments are given, expects the buffer to be large - * enough to hold the entire string and NULL terminator. Copies - * the contents of the string and the NULL terminator into the - * buffer. - */ - int Write(uint16_t* buffer) const; - - class V8EXPORT ExternalStringResourceBase { // NOLINT - public: - virtual ~ExternalStringResourceBase() {} - - protected: - ExternalStringResourceBase() {} - - /** - * Internally V8 will call this Dispose method when the external string - * resource is no longer needed. The default implementation will use the - * delete operator. This method can be overridden in subclasses to - * control how allocated external string resources are disposed. - */ - virtual void Dispose() { delete this; } - - }; /** * An ExternalStringResource is a wrapper around a two-byte string @@ -882,8 +806,7 @@ class V8EXPORT String : public Value { * ExternalStringResource to manage the life cycle of the underlying * buffer. Note that the string data must be immutable. */ - class V8EXPORT ExternalStringResource - : public ExternalStringResourceBase { + class V8EXPORT ExternalStringResource { public: /** * Override the destructor to manage the life cycle of the underlying @@ -901,6 +824,8 @@ class V8EXPORT String : public Value { */ virtual size_t length() const = 0; + virtual void Dispose() { delete this; } + protected: ExternalStringResource() {} }; @@ -927,9 +852,6 @@ class V8EXPORT String : public Value { /** Allocates a new string from 16-bit character codes.*/ static Handle New(const uint16_t* data, int length = -1); - /** Creates a symbol. Returns one if it exists already.*/ - static Handle NewSymbol(const char* data, int length = -1); - static Handle New(QV4::String *s); /** diff --git a/src/qml/qml/v4/v4.pri b/src/qml/qml/v4/v4.pri index b7dc9e6ab1..15f41d6f10 100644 --- a/src/qml/qml/v4/v4.pri +++ b/src/qml/qml/v4/v4.pri @@ -97,7 +97,6 @@ HEADERS += \ $$PWD/qv4unwindhelper_p-arm.h \ $$PWD/qv4serialize_p.h \ $$PWD/qv4v8_p.h \ - $$PWD/qcalculatehash_p.h \ $$PWD/qv4util_p.h \ $$PWD/qv4executableallocator_p.h \ $$PWD/qv4sequenceobject_p.h diff --git a/src/qml/qml/v8/qv8contextwrapper.cpp b/src/qml/qml/v8/qv8contextwrapper.cpp index 4bb89b86f8..fe4bfb8463 100644 --- a/src/qml/qml/v8/qv8contextwrapper.cpp +++ b/src/qml/qml/v8/qv8contextwrapper.cpp @@ -270,9 +270,9 @@ v8::Handle QV8ContextWrapper::Getter(v8::Handle property, QObject *scopeObject = resource->getScopeObject(); - QHashedV8String propertystring(property); + QHashedV4String propertystring(property->v4Value()); - if (context->imports && QV8Engine::startsWithUpper(property->v4Value().asString())) { + if (context->imports && property->v4Value().asString()->startsWithUpper()) { // Search for attached properties, enums and imported scripts QQmlTypeNameCache::Result r = context->imports->query(propertystring); @@ -393,7 +393,7 @@ v8::Handle QV8ContextWrapper::Setter(v8::Handle property, QV8Engine *engine = resource->engine; QObject *scopeObject = resource->getScopeObject(); - QHashedV8String propertystring(property); + QHashedV4String propertystring(property->v4Value()); QV8QObjectWrapper *qobjectWrapper = engine->qobjectWrapper(); diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 7589315a68..eda6850105 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -289,8 +289,6 @@ public: QV4::Value getOwnPropertyNames(const QV4::Value &o); void freezeObject(const QV4::Value &value); - static inline bool startsWithUpper(QV4::String *); - QVariant toVariant(const QV4::Value &value, int typeHint); QV4::Value fromVariant(const QVariant &); @@ -522,15 +520,6 @@ QV4::Value QV8Engine::bindingFlagKey() const return m_bindingFlagKey; } -// XXX Can this be made more optimal? It is called prior to resolving each and every -// unqualified name in QV8ContextWrapper. -bool QV8Engine::startsWithUpper(QV4::String *string) -{ - uint16_t c = string->toQString().at(0).unicode(); - return (c >= 'A' && c <= 'Z') || - (c > 127 && QChar::category(c) == QChar::Letter_Uppercase); -} - QV8Engine::Deletable *QV8Engine::extensionData(int index) const { if (index < m_extensionData.count()) diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index 93f7c9cb65..88f41e8c5d 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -312,8 +312,8 @@ void QV8QObjectWrapper::init(QV8Engine *engine) m_destroySymbol = QV4::Value::fromString(v4->newIdentifier("destroy")); m_hiddenObject = QV4::Value::fromObject(v4->newObject()); - m_toStringString = QHashedV8String(m_toStringSymbol.value()); - m_destroyString = QHashedV8String(m_destroySymbol.value()); + m_toStringString = QHashedV4String(m_toStringSymbol.value()); + m_destroyString = QHashedV4String(m_destroySymbol.value()); toStringHash = m_toStringString.hash(); destroyHash = m_destroyString.hash(); @@ -471,7 +471,7 @@ static v8::Handle LoadProperty(QV8Engine *engine, QObject *object, v8::Handle QV8QObjectWrapper::GetProperty(QV8Engine *engine, QObject *object, v8::Handle *objectHandle, - const QHashedV8String &property, + const QHashedV4String &property, QQmlContextData *context, QV8QObjectWrapper::RevisionMode revisionMode) { @@ -714,7 +714,7 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QQmlPropert } } -bool QV8QObjectWrapper::SetProperty(QV8Engine *engine, QObject *object, const QHashedV8String &property, QQmlContextData *context, +bool QV8QObjectWrapper::SetProperty(QV8Engine *engine, QObject *object, const QHashedV4String &property, QQmlContextData *context, v8::Handle value, QV8QObjectWrapper::RevisionMode revisionMode) { if (engine->qobjectWrapper()->m_toStringString == property || @@ -739,7 +739,7 @@ bool QV8QObjectWrapper::SetProperty(QV8Engine *engine, QObject *object, const QH if (!result->isWritable() && !result->isQList()) { QString error = QLatin1String("Cannot assign to read-only property \"") + - property.string()->v4Value().toQString() + QLatin1Char('\"'); + property.toString() + QLatin1Char('\"'); v8::ThrowException(v8::Exception::Error(engine->toString(error))); return true; } @@ -759,7 +759,7 @@ v8::Handle QV8QObjectWrapper::Getter(v8::Handle property, QObject *object = resource->object; - QHashedV8String propertystring(property); + QHashedV4String propertystring(property->v4Value()); QV8Engine *v8engine = resource->engine; QQmlContextData *context = v8engine->callingContext(); @@ -770,7 +770,7 @@ v8::Handle QV8QObjectWrapper::Getter(v8::Handle property, if (!result.IsEmpty()) return result; - if (QV8Engine::startsWithUpper(property->v4Value().asString())) { + if (property->v4Value().asString()->startsWithUpper()) { // Check for attached properties if (context && context->imports) { QQmlTypeNameCache::Result r = context->imports->query(propertystring); @@ -803,7 +803,7 @@ v8::Handle QV8QObjectWrapper::Setter(v8::Handle property, QObject *object = resource->object; - QHashedV8String propertystring(property); + QHashedV4String propertystring(property->v4Value()); QV8Engine *v8engine = resource->engine; QQmlContextData *context = v8engine->callingContext(); @@ -831,7 +831,7 @@ v8::Handle QV8QObjectWrapper::Query(v8::Handle property, QObject *object = resource->object; QQmlContextData *context = engine->callingContext(); - QHashedV8String propertystring(property); + QHashedV4String propertystring(property->v4Value()); QQmlPropertyData local; QQmlPropertyData *result = 0; diff --git a/src/qml/qml/v8/qv8qobjectwrapper_p.h b/src/qml/qml/v8/qv8qobjectwrapper_p.h index f25bec0eb7..426f1225f1 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper_p.h +++ b/src/qml/qml/v8/qv8qobjectwrapper_p.h @@ -102,8 +102,8 @@ public: static QObject *toQObject(QV8ObjectResource *); enum RevisionMode { IgnoreRevision, CheckRevision }; - inline v8::Handle getProperty(QObject *, const QHashedV8String &, QQmlContextData *, RevisionMode); - inline bool setProperty(QObject *, const QHashedV8String &, QQmlContextData *, v8::Handle, RevisionMode); + inline v8::Handle getProperty(QObject *, const QHashedV4String &, QQmlContextData *, RevisionMode); + inline bool setProperty(QObject *, const QHashedV4String &, QQmlContextData *, v8::Handle, RevisionMode); void registerWeakQObjectReference(QV8QObjectResource *resource) { @@ -123,8 +123,8 @@ private: v8::Handle newQObject(QObject *, QQmlData *, QV8Engine *); bool deleteWeakQObject(QV8QObjectResource *resource, bool calledFromEngineDtor = false); static v8::Handle GetProperty(QV8Engine *, QObject *, v8::Handle *, - const QHashedV8String &, QQmlContextData *, QV8QObjectWrapper::RevisionMode); - static bool SetProperty(QV8Engine *, QObject *, const QHashedV8String &, QQmlContextData *, + const QHashedV4String &, QQmlContextData *, QV8QObjectWrapper::RevisionMode); + static bool SetProperty(QV8Engine *, QObject *, const QHashedV4String &, QQmlContextData *, v8::Handle, QV8QObjectWrapper::RevisionMode); static v8::Handle Getter(v8::Handle property, const v8::AccessorInfo &info); @@ -148,8 +148,8 @@ private: QV4::PersistentValue m_signalHandlerConstructor; QV4::PersistentValue m_toStringSymbol; QV4::PersistentValue m_destroySymbol; - QHashedV8String m_toStringString; - QHashedV8String m_destroyString; + QHashedV4String m_toStringString; + QHashedV4String m_destroyString; QV4::PersistentValue m_hiddenObject; QHash m_connections; typedef QHash TaintedHash; @@ -157,7 +157,7 @@ private: QIntrusiveList m_javaScriptOwnedWeakQObjects; }; -v8::Handle QV8QObjectWrapper::getProperty(QObject *object, const QHashedV8String &string, +v8::Handle QV8QObjectWrapper::getProperty(QObject *object, const QHashedV4String &string, QQmlContextData *context, RevisionMode mode) { QQmlData *dd = QQmlData::get(object, false); @@ -169,7 +169,7 @@ v8::Handle QV8QObjectWrapper::getProperty(QObject *object, const QHas } } -bool QV8QObjectWrapper::setProperty(QObject *object, const QHashedV8String &string, +bool QV8QObjectWrapper::setProperty(QObject *object, const QHashedV4String &string, QQmlContextData *context, v8::Handle value, RevisionMode mode) { QQmlData *dd = QQmlData::get(object, false); diff --git a/src/qml/qml/v8/qv8typewrapper.cpp b/src/qml/qml/v8/qv8typewrapper.cpp index e7660f7306..c9699767a4 100644 --- a/src/qml/qml/v8/qv8typewrapper.cpp +++ b/src/qml/qml/v8/qv8typewrapper.cpp @@ -160,7 +160,7 @@ v8::Handle QV8TypeWrapper::Getter(v8::Handle property, QObject *object = resource->object; - QHashedV8String propertystring(property); + QHashedV4String propertystring(property->v4Value()); if (resource->type) { QQmlType *type = resource->type; @@ -174,7 +174,7 @@ v8::Handle QV8TypeWrapper::Getter(v8::Handle property, QObject *qobjectSingleton = siinfo->qobjectApi(e); if (qobjectSingleton) { // check for enum value - if (QV8Engine::startsWithUpper(property->v4Value().asString())) { + if (property->v4Value().asString()->startsWithUpper()) { if (resource->mode == IncludeEnums) { QString name = property->v4Value().toQString(); @@ -207,7 +207,7 @@ v8::Handle QV8TypeWrapper::Getter(v8::Handle property, } else { - if (QV8Engine::startsWithUpper(property->v4Value().asString())) { + if (property->v4Value().asString()->startsWithUpper()) { bool ok = false; int value = type->enumValue(propertystring, &ok); if (ok) @@ -271,7 +271,7 @@ v8::Handle QV8TypeWrapper::Setter(v8::Handle property, QV8Engine *v8engine = resource->engine; QQmlContextData *context = v8engine->callingContext(); - QHashedV8String propertystring(property); + QHashedV4String propertystring(property->v4Value()); QQmlType *type = resource->type; if (type && !type->isSingleton() && resource->object) { diff --git a/src/qml/qml/v8/qv8valuetypewrapper.cpp b/src/qml/qml/v8/qv8valuetypewrapper.cpp index cf2310db92..9bf1169c21 100644 --- a/src/qml/qml/v8/qv8valuetypewrapper.cpp +++ b/src/qml/qml/v8/qv8valuetypewrapper.cpp @@ -125,7 +125,7 @@ void QV8ValueTypeWrapper::init(QV8Engine *engine) m_constructor = ft->GetFunction()->v4Value(); m_toStringSymbol = QV4::Value::fromString(QV8Engine::getV4(engine)->newIdentifier(QStringLiteral("toString"))); - m_toStringString = QHashedV8String(m_toStringSymbol.value()); + m_toStringString = QHashedV4String(m_toStringSymbol.value()); toStringHash = m_toStringString.hash(); } @@ -282,7 +282,7 @@ v8::Handle QV8ValueTypeWrapper::Getter(v8::Handle propert QV8ValueTypeResource *r = v8_resource_cast(info.This()); if (!r) return v8::Handle(); - QHashedV8String propertystring(property); + QHashedV4String propertystring(property->v4Value()); { // Comparing the hash first actually makes a measurable difference here, at least on x86 diff --git a/src/qml/qml/v8/qv8valuetypewrapper_p.h b/src/qml/qml/v8/qv8valuetypewrapper_p.h index ed97b1325d..c6c87750fa 100644 --- a/src/qml/qml/v8/qv8valuetypewrapper_p.h +++ b/src/qml/qml/v8/qv8valuetypewrapper_p.h @@ -100,7 +100,7 @@ private: QV4::PersistentValue m_constructor; QV4::PersistentValue m_toString; QV4::PersistentValue m_toStringSymbol; - QHashedV8String m_toStringString; + QHashedV4String m_toStringString; }; QT_END_NAMESPACE diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index d44773cb78..6666f63387 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -105,7 +105,7 @@ const ListLayout::Role &ListLayout::getRoleOrCreate(const QString &key, Role::Da const ListLayout::Role &ListLayout::getRoleOrCreate(v8::Handle key, Role::DataType type) { - QHashedV8String hashedKey(key); + QHashedV4String hashedKey(key->v4Value()); QStringHash::Node *node = roleHash.findNode(hashedKey); if (node) { const Role &r = *node->value; @@ -114,9 +114,7 @@ const ListLayout::Role &ListLayout::getRoleOrCreate(v8::Handle key, return r; } - QString qkey; - qkey.resize(key->Length()); - key->Write(reinterpret_cast(qkey.data())); + QString qkey = key->asQString(); return createRole(qkey, type); } @@ -244,7 +242,7 @@ const ListLayout::Role *ListLayout::getExistingRole(const QString &key) const ListLayout::Role *ListLayout::getExistingRole(v8::Handle key) { Role *r = 0; - QHashedV8String hashedKey(key); + QHashedV4String hashedKey(key->v4Value()); QStringHash::Node *node = roleHash.findNode(hashedKey); if (node) r = node->value; @@ -430,9 +428,7 @@ void ListModel::set(int elementIndex, v8::Handle object, QVectorIsString()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String); v8::Handle jsString = propertyValue->ToString(); - QString qstr; - qstr.resize(jsString->Length()); - jsString->Write(reinterpret_cast(qstr.data())); + QString qstr = jsString->asQString(); roleIndex = e->setStringProperty(r, qstr); } else if (propertyValue->IsNumber()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Number); @@ -499,9 +495,7 @@ void ListModel::set(int elementIndex, v8::Handle object, QV8Engine * const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String); if (r.type == ListLayout::Role::String) { v8::Handle jsString = propertyValue->ToString(); - QString qstr; - qstr.resize(jsString->Length()); - jsString->Write(reinterpret_cast(qstr.data())); + QString qstr = jsString->asQString(); e->setStringPropertyFast(r, qstr); } } else if (propertyValue->IsNumber()) { @@ -1173,9 +1167,7 @@ int ListElement::setJsProperty(const ListLayout::Role &role, v8::HandleIsString()) { v8::Handle jsString = d->ToString(); - QString qstr; - qstr.resize(jsString->Length()); - jsString->Write(reinterpret_cast(qstr.data())); + QString qstr = jsString->asQString(); roleIndex = setStringProperty(role, qstr); } else if (d->IsNumber()) { roleIndex = setDoubleProperty(role, d->NumberValue()); -- cgit v1.2.3