use a property for index length because its slow to get the first property or get the length of a hash.

This commit is contained in:
jfgirard 2012-11-12 13:22:28 -05:00
parent ab85108836
commit 471816120b

View File

@ -37,6 +37,7 @@ L.Mixin.Events = {
events[tIndex][leafletId].push(evt); events[tIndex][leafletId].push(evt);
} else { } else {
events[tIndex][leafletId] = [evt]; events[tIndex][leafletId] = [evt];
events[types[i] + '_idx_len'] = (events[types[i] + '_idx_len'] || 0) + 1;
} }
} else { } else {
events[types[i]] = events[types[i]] || []; events[types[i]] = events[types[i]] || [];
@ -52,14 +53,8 @@ L.Mixin.Events = {
if ((type in this[key]) && this[key][type].length > 0) { if ((type in this[key]) && this[key][type].length > 0) {
return true; return true;
} else { } else {
var typeIdx = type + '_idx'; if(this[key][type + '_idx_len'] > 0){
if (typeIdx in this[key]) { return true;
for (var leafletId in this[key][typeIdx]) {
if (this[key][typeIdx].hasOwnProperty(leafletId)) {
//atleast one id
return true;
}
}
} }
} }
} }
@ -96,6 +91,7 @@ L.Mixin.Events = {
} }
if (context && context._leaflet_id && listeners.length === 0) { if (context && context._leaflet_id && listeners.length === 0) {
delete events[types[i] + '_idx'][context._leaflet_id]; delete events[types[i] + '_idx'][context._leaflet_id];
events[types[i] + '_idx_len'] = (events[types[i] + '_idx_len'] || 1) - 1;
} }
} }
} }