mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Fix performance regressions in tree.js (fixes #2396)
This commit is contained in:
@@ -19,21 +19,19 @@ iD.Tree = function(head) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateParents(entity, insertions, memo) {
|
function updateParents(entity, insertions, memo) {
|
||||||
if (memo && memo[entity.id]) return;
|
|
||||||
memo = memo || {};
|
|
||||||
memo[entity.id] = true;
|
|
||||||
|
|
||||||
head.parentWays(entity).forEach(function(parent) {
|
head.parentWays(entity).forEach(function(parent) {
|
||||||
if (rectangles[parent.id]) {
|
if (rectangles[parent.id]) {
|
||||||
rtree.remove(rectangles[parent.id]);
|
rtree.remove(rectangles[parent.id]);
|
||||||
insertions.push(parent);
|
insertions[parent.id] = parent;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
head.parentRelations(entity).forEach(function(parent) {
|
head.parentRelations(entity).forEach(function(parent) {
|
||||||
|
if (memo[entity.id]) return;
|
||||||
|
memo[entity.id] = true;
|
||||||
if (rectangles[parent.id]) {
|
if (rectangles[parent.id]) {
|
||||||
rtree.remove(rectangles[parent.id]);
|
rtree.remove(rectangles[parent.id]);
|
||||||
insertions.push(parent);
|
insertions[parent.id] = parent;
|
||||||
}
|
}
|
||||||
updateParents(parent, insertions, memo);
|
updateParents(parent, insertions, memo);
|
||||||
});
|
});
|
||||||
@@ -42,18 +40,19 @@ iD.Tree = function(head) {
|
|||||||
var tree = {};
|
var tree = {};
|
||||||
|
|
||||||
tree.rebase = function(entities) {
|
tree.rebase = function(entities) {
|
||||||
var insertions = [];
|
var insertions = {};
|
||||||
|
|
||||||
|
for (var i = 0; i < entities.length; i++) {
|
||||||
|
var entity = entities[i];
|
||||||
|
|
||||||
entities.forEach(function(entity) {
|
|
||||||
if (head.entities.hasOwnProperty(entity.id) || rectangles[entity.id])
|
if (head.entities.hasOwnProperty(entity.id) || rectangles[entity.id])
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
insertions.push(entity);
|
insertions[entity.id] = entity;
|
||||||
updateParents(entity, insertions);
|
updateParents(entity, insertions, {});
|
||||||
});
|
}
|
||||||
|
|
||||||
insertions = _.unique(insertions).map(entityRectangle);
|
rtree.load(_.map(insertions, entityRectangle));
|
||||||
rtree.load(insertions);
|
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
};
|
};
|
||||||
@@ -61,7 +60,7 @@ iD.Tree = function(head) {
|
|||||||
tree.intersects = function(extent, graph) {
|
tree.intersects = function(extent, graph) {
|
||||||
if (graph !== head) {
|
if (graph !== head) {
|
||||||
var diff = iD.Difference(head, graph),
|
var diff = iD.Difference(head, graph),
|
||||||
insertions = [];
|
insertions = {};
|
||||||
|
|
||||||
head = graph;
|
head = graph;
|
||||||
|
|
||||||
@@ -72,16 +71,15 @@ iD.Tree = function(head) {
|
|||||||
|
|
||||||
diff.modified().forEach(function(entity) {
|
diff.modified().forEach(function(entity) {
|
||||||
rtree.remove(rectangles[entity.id]);
|
rtree.remove(rectangles[entity.id]);
|
||||||
insertions.push(entity);
|
insertions[entity.id] = entity;
|
||||||
updateParents(entity, insertions);
|
updateParents(entity, insertions);
|
||||||
});
|
});
|
||||||
|
|
||||||
diff.created().forEach(function(entity) {
|
diff.created().forEach(function(entity) {
|
||||||
insertions.push(entity);
|
insertions[entity.id] = entity;
|
||||||
});
|
});
|
||||||
|
|
||||||
insertions = _.unique(insertions).map(entityRectangle);
|
rtree.load(_.map(insertions, entityRectangle));
|
||||||
rtree.load(insertions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rtree.search(extentRectangle(extent)).map(function(rect) {
|
return rtree.search(extentRectangle(extent)).map(function(rect) {
|
||||||
|
|||||||
Reference in New Issue
Block a user