aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextnodeengine_p.h
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2015-03-02 09:51:44 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2015-03-09 08:29:51 +0000
commit11a595e30615943cd6c63f08cc44cde7861112eb (patch)
tree536e57c5ea097b95346d9bd5f8ab844297d98e0b /src/quick/items/qquicktextnodeengine_p.h
parent2a28bebdc8548c1171a3f255651edafe685da003 (diff)
Reduce number of allocations when constructing text nodes
In cases where you have a huge number of text elements that can be merged, we would do a lot of reallocations (one per node that would be merged into another). As the number of merges grew, this seemed to converge at about 50% of the time spent in updatePaintNode() in the text classes. We can almost eliminate this cost by only doing one realloc per node that will actually end up in the scene graph. This patch does a first pass where it simply bundles together nodes that can be merged. Then it does a second pass where it actually merges the nodes. In this second pass it can easily precount the required size of the arrays and we can limit it to a single realloc. Task-number: QTBUG-37365 Change-Id: I4e44c01cd83df39304cbbce34f3b8f773763e091 Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'src/quick/items/qquicktextnodeengine_p.h')
-rw-r--r--src/quick/items/qquicktextnodeengine_p.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/quick/items/qquicktextnodeengine_p.h b/src/quick/items/qquicktextnodeengine_p.h
index 3441a5a973..178454b19e 100644
--- a/src/quick/items/qquicktextnodeengine_p.h
+++ b/src/quick/items/qquicktextnodeengine_p.h
@@ -102,6 +102,33 @@ public:
static void inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree, QVarLengthArray<int> *sortedIndexes, int currentIndex = 0);
};
+ struct BinaryTreeNodeKey
+ {
+ BinaryTreeNodeKey(QFontEngine *fe,
+ QQuickDefaultClipNode *cn,
+ QRgb col,
+ int selState)
+ : fontEngine(fe)
+ , clipNode(cn)
+ , color(col)
+ , selectionState(selState)
+ {
+ }
+
+ bool operator==(const BinaryTreeNodeKey &otherKey) const
+ {
+ return fontEngine == otherKey.fontEngine
+ && clipNode == otherKey.clipNode
+ && color == otherKey.color
+ && selectionState == otherKey.selectionState;
+ }
+
+ QFontEngine *fontEngine;
+ QQuickDefaultClipNode *clipNode;
+ QRgb color;
+ int selectionState;
+ };
+
QQuickTextNodeEngine() : m_hasSelection(false), m_hasContents(false) {}
bool hasContents() const { return m_hasContents; }
@@ -141,6 +168,8 @@ public:
int start, int end,
int selectionStart, int selectionEnd);
+ void mergeProcessedNodes(QList<BinaryTreeNode *> *regularNodes,
+ QList<BinaryTreeNode *> *imageNodes);
void addToSceneGraph(QQuickTextNode *parent,
QQuickText::TextStyle style = QQuickText::Normal,
const QColor &styleColor = QColor());