From d3c4ec36712105354e810bd4224ab833547a5d60 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 22 Feb 2012 05:49:06 +0100 Subject: [PATCH] Global xpaths optimization. This is actually faster. --- 4chan_x.user.js | 4 ++-- script.coffee | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 113469b95..4953abbad 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -392,7 +392,7 @@ }, x: function(path, root) { if (root == null) root = d.body; - return d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue; + return d.evaluate(path, root, null, 8, null).singleNodeValue; }, replace: function(root, el) { return root.parentNode.replaceChild(el, root); @@ -641,7 +641,7 @@ comment: function(root) { var i, len, node, nodes, text; text = []; - nodes = d.evaluate('.//node()', root.lastChild, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); + nodes = d.evaluate('.//node()', root.lastChild, null, 7, null); i = 0; len = nodes.snapshotLength; while (i < len) { diff --git a/script.coffee b/script.coffee index ba597d389..08c981e07 100644 --- a/script.coffee +++ b/script.coffee @@ -301,7 +301,8 @@ $.extend $, $.add d.head, style style x: (path, root=d.body) -> - d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null). + # XPathResult.ANY_UNORDERED_NODE_TYPE is 8 + d.evaluate(path, root, null, 8, null). singleNodeValue replace: (root, el) -> root.parentNode.replaceChild el, root @@ -552,7 +553,8 @@ filter = sub.textContent comment: (root) -> text = [] - nodes = d.evaluate './/node()', root.lastChild, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null + # XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 7 + nodes = d.evaluate './/node()', root.lastChild, null, 7, null i = 0 len = nodes.snapshotLength while i < len