Micro optimization of StringPool
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>
Thu, 13 Dec 2012 14:11:21 +0000 (15:11 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Fri, 14 Dec 2012 13:24:44 +0000 (14:24 +0100)
In destructor we do not need to create a copy off all pointers.

By hiding StringPool::strings in class private
section we reduce risk of it being accidentally copied.

Change-Id: I1b9df6bf9e49bd6926e84b8eac6b3d904277e50a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qmljs_engine.cpp
qmljs_engine.h
qmljs_objects.h
qv4mm.cpp

index 1940a4f..78fd64b 100644 (file)
 namespace QQmlJS {
 namespace VM {
 
-struct StringPool
+class StringPool
 {
     QHash<QString, String*> strings;
-
+public:
     ~StringPool()
-    { qDeleteAll(strings.values()); }
+    {
+        qDeleteAll(strings);
+    }
 
     String *newString(const QString &s)
     {
index 94093cb..dd856f6 100644 (file)
@@ -154,7 +154,7 @@ struct ExecutionEngine
     QVector<ExceptionHandler> unwindStack;
     Value exception;
 
-    QScopedPointer<struct StringPool> stringPool;
+    QScopedPointer<class StringPool> stringPool;
     QVector<Function *> functions;
 
     ExecutionEngine(MemoryManager *memoryManager, EvalISelFactory *iselFactory);
index 18b5271..eacbc00 100644 (file)
@@ -136,7 +136,7 @@ struct String {
     }
 
 private:
-    friend struct StringPool;
+    friend class StringPool;
     String(const QString &text)
         : _text(text), _hashValue(0) {}
 
index 322ad97..a5215cd 100644 (file)
--- a/qv4mm.cpp
+++ b/qv4mm.cpp
@@ -45,6 +45,7 @@ using namespace QQmlJS::VM;
 
 static const std::size_t CHUNK_SIZE = 65536;
 
+class StringPool;
 struct MemoryManager::Data
 {
     bool enableGC;