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