From 46a642ac96fc0471941b0df23518f380c1745bab Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 31 Dec 2015 21:03:03 -0500 Subject: [PATCH] WIP for 2887, and perf improvements (avoid unnecessary caching) --- js/id/renderer/features.js | 52 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/js/id/renderer/features.js b/js/id/renderer/features.js index e4ce089e5..115374eb4 100644 --- a/js/id/renderer/features.js +++ b/js/id/renderer/features.js @@ -279,39 +279,42 @@ iD.Features = function(context) { }; features.getMatches = function(entity, resolver, geometry) { - var ent = iD.Entity.key(entity); + if (geometry === 'vertex' || geometry === 'relation') return {}; + + var ent = iD.Entity.key(entity), + matches = {}, + hasMatch = false; if (!_cache[ent]) { _cache[ent] = {}; } if (!_cache[ent].matches) { - var matches = {}, - hasMatch = false; - - if (!(geometry === 'vertex' || geometry === 'relation')) { + if (_.isEmpty(entity.tags)) { + matches.others = true; + } + else { for (var i = 0; i < _keys.length; i++) { - if (_keys[i] === 'others') { if (hasMatch) continue; - // If the entity is a way that has not matched any other - // feature type, see if it has a parent relation, and if so, - // match whatever feature types the parent has matched. - // (The way is a member of a multipolygon.) - // - // IMPORTANT: - // For this to work, getMatches must be called on relations before ways. - // - if (entity.type === 'way') { - var parents = features.getParents(entity, resolver, geometry); - if (parents.length === 1) { - var pkey = iD.Entity.key(parents[0]); - if (_cache[pkey] && _cache[pkey].matches) { - matches = _.clone(_cache[pkey].matches); - continue; - } - } - } + // // If the entity is a way that has not matched any other + // // feature type, see if it has a parent relation, and if so, + // // match whatever feature types the parent has matched. + // // (The way is a member of a multipolygon.) + // // + // // IMPORTANT: + // // For this to work, getMatches must be called on relations before ways. + // // + // if (entity.type === 'way') { + // var parents = features.getParents(entity, resolver, geometry); + // if (parents.length === 1) { + // var pkey = iD.Entity.key(parents[0]); + // if (_cache[pkey] && _cache[pkey].matches) { + // matches = _.clone(_cache[pkey].matches); + // continue; + // } + // } + // } } if (_features[_keys[i]].filter(entity, resolver, geometry)) { @@ -321,6 +324,7 @@ iD.Features = function(context) { } _cache[ent].matches = matches; } + return _cache[ent].matches; };