Improve memory usage of QQuickTextNode.
authorMichael Brasser <michael.brasser@live.com>
Thu, 1 Aug 2013 17:38:36 +0000 (12:38 -0500)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 6 Aug 2013 06:10:46 +0000 (08:10 +0200)
The typical number of BinaryTreeNodes needed for a text line should be
much lower than 256.

Task-number: QTBUG-32770
Change-Id: I85aa161eb7cb6e55657213304b7577a0a33f1b67
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
src/quick/items/qquicktextnodeengine.cpp
src/quick/items/qquicktextnodeengine_p.h

index 7bbfd1b..ce45063 100644 (file)
@@ -58,7 +58,7 @@
 
 QT_BEGIN_NAMESPACE
 
-void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
+void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
                                              QQuickTextNode::Decorations decorations, const QColor &textColor,
                                              const QColor &backgroundColor, const QPointF &position)
 {
@@ -78,7 +78,7 @@ void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode
                                       textColor, backgroundColor, position, ascent));
 }
 
-void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode> *binaryTree, const BinaryTreeNode &binaryTreeNode)
+void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const BinaryTreeNode &binaryTreeNode)
 {
     int newIndex = binaryTree->size();
     binaryTree->append(binaryTreeNode);
@@ -106,7 +106,7 @@ void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode
     }
 }
 
-void QQuickTextNodeEngine::BinaryTreeNode::inOrder(const QVarLengthArray<BinaryTreeNode> &binaryTree,
+void QQuickTextNodeEngine::BinaryTreeNode::inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree,
                                               QVarLengthArray<int> *sortedIndexes, int currentIndex)
 {
     Q_ASSERT(currentIndex < binaryTree.size());
index 6a98d6b..9de71c6 100644 (file)
@@ -103,13 +103,13 @@ public:
         int leftChildIndex;
         int rightChildIndex;
 
-        static void insert(QVarLengthArray<BinaryTreeNode> *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
+        static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
         { insert(binaryTree, BinaryTreeNode(rect, image, selectionState, ascent)); }
 
-        static void insert(QVarLengthArray<BinaryTreeNode> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
+        static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
                            QQuickTextNode::Decorations decorations, const QColor &textColor, const QColor &backgroundColor, const QPointF &position);
-        static void insert(QVarLengthArray<BinaryTreeNode> *binaryTree, const BinaryTreeNode &binaryTreeNode);
-        static void inOrder(const QVarLengthArray<BinaryTreeNode> &binaryTree, QVarLengthArray<int> *sortedIndexes, int currentIndex = 0);
+        static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const BinaryTreeNode &binaryTreeNode);
+        static void inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree, QVarLengthArray<int> *sortedIndexes, int currentIndex = 0);
     };
 
     QQuickTextNodeEngine() : m_hasSelection(false), m_hasContents(false) {}
@@ -216,7 +216,7 @@ private:
 
     QList<QPair<QRectF, QColor> > m_backgrounds;
     QList<QRectF> m_selectionRects;
-    QVarLengthArray<BinaryTreeNode> m_currentLineTree;
+    QVarLengthArray<BinaryTreeNode, 16> m_currentLineTree;
 
     QList<TextDecoration> m_lines;
     QVector<BinaryTreeNode> m_processedNodes;