aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativepropertycache.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2011-07-14 15:35:39 +1000
committerQt by Nokia <qt-info@nokia.com>2011-08-30 13:18:28 +0200
commitf242ef892818f8230c8f3b49d155e0e20fe46679 (patch)
treeb15efd47dcfef80c4f7ef93ebfac538c2f960329 /src/declarative/qml/qdeclarativepropertycache.cpp
parent3d958cec8d53094a1bbab895377e451b07716e1f (diff)
Improve QStringHash
We now support reserving nodes, and keys that are ASCII strings. Change-Id: I9cc04438a1e9ceee1081cb1216e0273227551222 Reviewed-on: http://codereview.qt.nokia.com/3745 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/declarative/qml/qdeclarativepropertycache.cpp')
-rw-r--r--src/declarative/qml/qdeclarativepropertycache.cpp57
1 files changed, 40 insertions, 17 deletions
diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp
index d2148ad874..0d44b58297 100644
--- a/src/declarative/qml/qdeclarativepropertycache.cpp
+++ b/src/declarative/qml/qdeclarativepropertycache.cpp
@@ -278,14 +278,14 @@ QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObj
return rv;
}
-QDeclarativePropertyCache *QDeclarativePropertyCache::copy()
+QDeclarativePropertyCache *QDeclarativePropertyCache::copy(int reserve)
{
QDeclarativePropertyCache *cache = new QDeclarativePropertyCache(engine);
cache->parent = this;
cache->parent->addref();
cache->propertyIndexCacheStart = propertyIndexCache.count() + propertyIndexCacheStart;
cache->methodIndexCacheStart = methodIndexCache.count() + methodIndexCacheStart;
- cache->stringCache = stringCache;
+ cache->stringCache.copyAndReserve(stringCache, reserve);
cache->allowedRevisionCache = allowedRevisionCache;
// We specifically do *NOT* copy the constructor
@@ -324,10 +324,8 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb
// Extract method name
const char *signature = m.signature();
const char *cptr = signature;
- while (*cptr != '(') { Q_ASSERT(*cptr != 0); ++cptr; }
- QString str = dynamicMetaObject?QString::fromUtf8(signature, cptr - signature):
- QString::fromLatin1(signature, cptr - signature);
- QHashedString methodName(str);
+ bool utf8 = false;
+ while (*cptr != '(') { Q_ASSERT(*cptr != 0); utf8 |= *cptr & 0x80; ++cptr; }
Data *data = &methodIndexCache[ii - methodIndexCacheStart];
@@ -342,15 +340,25 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb
data->metaObjectOffset = allowedRevisionCache.count() - 1;
- if (Data **old = stringCache.value(methodName)) {
+ Data **old = 0;
+
+ if (utf8) {
+ QHashedString methodName(QString::fromUtf8(signature, cptr - signature));
+ old = stringCache.value(methodName);
+ stringCache.insert(methodName, data);
+ } else {
+ QHashedCStringRef methodName(signature, cptr - signature);
+ old = stringCache.value(methodName);
+ stringCache.insert(methodName, data);
+ }
+
+ if (old) {
// We only overload methods in the same class, exactly like C++
if ((*old)->flags & Data::IsFunction && (*old)->coreIndex >= methodOffset)
data->relatedIndex = (*old)->coreIndex;
data->overrideIndexIsProperty = !bool((*old)->flags & Data::IsFunction);
data->overrideIndex = (*old)->coreIndex;
}
-
- stringCache.insert(methodName, data);
}
int propCount = metaObject->propertyCount();
@@ -362,9 +370,10 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb
if (!p.isScriptable())
continue;
- QString str = dynamicMetaObject?QString::fromUtf8(p.name()):
- QString::fromLatin1(p.name());
- QHashedString propName(str);
+ const char *str = p.name();
+ bool utf8 = false;
+ const char *cptr = str;
+ while (*cptr != 0) { utf8 |= *cptr & 0x80; ++cptr; }
Data *data = &propertyIndexCache[ii - propertyIndexCacheStart];
@@ -376,12 +385,22 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb
data->metaObjectOffset = allowedRevisionCache.count() - 1;
- if (Data **old = stringCache.value(propName)) {
+ Data **old = 0;
+
+ if (utf8) {
+ QHashedString propName(QString::fromUtf8(str, cptr - str));
+ old = stringCache.value(propName);
+ stringCache.insert(propName, data);
+ } else {
+ QHashedCStringRef propName(str, cptr - str);
+ old = stringCache.value(propName);
+ stringCache.insert(propName, data);
+ }
+
+ if (old) {
data->overrideIndexIsProperty = !bool((*old)->flags & Data::IsFunction);
data->overrideIndex = (*old)->coreIndex;
}
-
- stringCache.insert(propName, data);
}
}
@@ -417,8 +436,12 @@ void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaOb
Q_ASSERT(stringCache.isEmpty());
// Optimization to prevent unnecessary reallocation of lists
- propertyIndexCache.reserve(metaObject->propertyCount());
- methodIndexCache.reserve(metaObject->methodCount());
+ int pc = metaObject->propertyCount();
+ int mc = metaObject->methodCount();
+ propertyIndexCache.reserve(pc);
+ methodIndexCache.reserve(mc);
+
+ stringCache.reserve(pc + mc);
updateRecur(engine,metaObject);
}