From d3cc822f98f7bf8e959f347de92bdb851ddd9e25 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 13 Dec 2013 17:30:28 +0100 Subject: [PATCH] Do not ascend when node has more siblings --- src/ol/structs/rbush.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index e0bdc81819..fe8c8e4153 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -609,8 +609,9 @@ ol.structs.RBush.prototype.remove_ = function(extent, value) { var path = [node]; /** @type {Array.} */ var indexes = [0]; - var child, children, i, ii; + var childrenDone, child, children, i, ii; while (path.length > 0) { + childrenDone = false; goog.asserts.assert(node.height > 0); if (node.height == 1) { children = node.children; @@ -622,8 +623,7 @@ ol.structs.RBush.prototype.remove_ = function(extent, value) { return; } } - node = path.pop(); - index = indexes.pop(); + childrenDone = true; } else if (index < node.children.length) { child = node.children[index]; if (ol.extent.containsExtent(child.extent, extent)) { @@ -635,8 +635,16 @@ ol.structs.RBush.prototype.remove_ = function(extent, value) { ++index; } } else { - node = path.pop(); - index = indexes.pop(); + childrenDone = true; + } + if (childrenDone === true) { + var lastPathIndex = path.length - 1; + node = path[lastPathIndex]; + index = ++indexes[lastPathIndex]; + if (index > node.children.length) { + path.pop(); + indexes.pop(); + } } } };