From 155d2c6867f07f5ef415ebddedc8c472311d5015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Thu, 8 Oct 2015 16:34:07 +0200 Subject: [PATCH] Reduce reflows --- cq-prolyfill.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/cq-prolyfill.js b/cq-prolyfill.js index da133b5..c3878a6 100644 --- a/cq-prolyfill.js +++ b/cq-prolyfill.js @@ -477,7 +477,7 @@ function updateClasses(clearContainerCache) { } write(elementsTree); - function read(treeNodes) { + function read(treeNodes, dontMarkAsDone) { var hasChanges = false; treeNodes.forEach(function(node) { if (!node._done) { @@ -487,14 +487,11 @@ function updateClasses(clearContainerCache) { node._changes.push([queryMatches, query]); } }); - node._done = true; - } - if (node._changes.length) { - hasChanges = true; - } - else { - hasChanges = read(node._children); + node._done = !dontMarkAsDone; } + hasChanges = read(node._children, dontMarkAsDone || node._changes.length) + || node._changes.length + || hasChanges; }); return hasChanges; }