Small parentWays, parentRelations perf improvements

This commit is contained in:
Ansis Brammanis
2013-01-30 16:09:15 -05:00
parent a317859b0f
commit 2fa48df9a1
3 changed files with 12 additions and 9 deletions
+10 -7
View File
@@ -24,6 +24,7 @@ iD.Graph = function(other, mutable) {
this.transients = {};
this._childNodes = {};
this.getEntity = _.bind(this.entity, this);
if (!mutable) {
this.freeze();
@@ -48,19 +49,21 @@ iD.Graph.prototype = {
},
parentWays: function(entity) {
return _.map(this._parentWays[entity.id], _.bind(this.entity, this));
return _.map(this._parentWays[entity.id], this.getEntity);
},
isPoi: function(entity) {
return this.parentWays(entity).length === 0;
var parentWays = this._parentWays[entity.id];
return !parentWays || parentWays.length === 0;
},
isShared: function(entity) {
var parentWays = this._parentWays[entity.id];
return parentWays && parentWays.length > 1;
},
parentRelations: function(entity) {
return _.map(this._parentRels[entity.id], _.bind(this.entity, this));
var ent, id, parents;
return this._parentRels[entity.id] || [];
return _.map(this._parentRels[entity.id], this.getEntity);
},
childNodes: function(entity) {
+1 -1
View File
@@ -64,7 +64,7 @@ iD.Map = function() {
for (var i = 0; i < parents.length; i++) {
var parent = parents[i];
if (only[parent.id] === undefined) {
only[parent.id] = graph.entity(parent.id);
only[parent.id] = parent;
addParents(graph.parentRelations(parent));
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ iD.svg.Vertices = function(projection) {
groups.attr('transform', iD.svg.PointTransform(projection))
.call(iD.svg.TagClasses())
.call(iD.svg.MemberClasses(graph))
.classed('shared', function(entity) { return graph.parentWays(entity).length > 1; });
.classed('shared', function(entity) { return graph.isShared(entity); });
// Selecting the following implicitly
// sets the data (vertix entity) on the elements