mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-26 09:57:50 +02:00
Optimize difference and parentWays
This commit is contained in:
+10
-5
@@ -46,15 +46,20 @@ iD.Graph.prototype = {
|
||||
},
|
||||
|
||||
parentWays: function(id) {
|
||||
// This is slow and a bad hack.
|
||||
return _.filter(this.entities, function(e) {
|
||||
return e && e.type === 'way' && e.nodes.indexOf(id) !== -1;
|
||||
});
|
||||
var o = [];
|
||||
for (var i in this.entities) {
|
||||
if (this.entities[i] &&
|
||||
this.entities[i].type === 'way' &&
|
||||
this.entities[i].nodes.indexOf(id) !== -1) {
|
||||
o.push(this.entities[i]);
|
||||
}
|
||||
}
|
||||
return o;
|
||||
},
|
||||
|
||||
parentRelations: function(id) {
|
||||
// This is slow and a bad hack.
|
||||
return _.filter(this.entities, function(e) {
|
||||
return _.filter(this.entities, function buildParentRelations(e) {
|
||||
return e && e.type === 'relation' &&
|
||||
_.pluck(e.members, 'id').indexOf(id) !== -1;
|
||||
});
|
||||
|
||||
@@ -75,17 +75,19 @@ iD.Map = function() {
|
||||
filter = d3.functor(true);
|
||||
} else {
|
||||
var only = {};
|
||||
difference.forEach(function buildDifference(id) {
|
||||
for (var j = 0; j < difference.length; j++) {
|
||||
var id = difference[j];
|
||||
only[id] = graph.fetch(id);
|
||||
if (only[id] && only[id].type === 'node') {
|
||||
graph.parentWays(id).forEach(function buildOnly(parent) {
|
||||
var parents = graph.parentWays(id);
|
||||
for (var k = 0; k < parents.length; k++) {
|
||||
// Don't re-fetch parents
|
||||
if (only[parent.id] === undefined) {
|
||||
only[parent.id] = graph.fetch(parent.id);
|
||||
if (only[parents[k].id] === undefined) {
|
||||
only[parent.id] = graph.fetch(parents[k].id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
all = _.compact(_.values(only));
|
||||
filter = function(d) { return d.accuracy ? d.way in only : d.id in only; };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user