Skip to content

Commit

Permalink
Speed up XPath execution
Browse files Browse the repository at this point in the history
JSON.stringify calls in two nested cycles are very resource-intensive.
However, the returned value of these calls is the same during loops.
It seems they could be moved outside the loops safely.

Fixes #1473.
  • Loading branch information
vsemozhetbyt authored and domenic committed May 15, 2016
1 parent 306805a commit f8ad3b9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/jsdom/level3/xpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,10 @@ module.exports = core => {
finalize: function() {
if (null == this.nextPos) return this;
console.assert(0 === this.nextPos.length);
var lastsJSON = JSON.stringify(this.lasts);
for (var i = 0; i < this.lasts.length; ++i) {
for (var j = 0; j < this.lasts[i].length; ++j) {
console.assert(null != this.lasts[i][j], i + ',' + j + ':' + JSON.stringify(this.lasts));
console.assert(null != this.lasts[i][j], i + ',' + j + ':' + lastsJSON);
}
}
this.pushSeries = this.popSeries = this.addNode = function() {
Expand Down

0 comments on commit f8ad3b9

Please sign in to comment.