diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 87c992ef..a6b89483 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -292,7 +292,8 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({ process(); } else { - var needsClustering = this._needsClustering; + var needsClustering = new Array(l - offset); // improve performance by preallocating the maximum size of our array + var tail = 0; for (; offset < l; offset++) { m = layersArray[offset]; @@ -318,8 +319,11 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({ continue; } - needsClustering.push(m); + needsClustering[tail++] = m; } + + needsClustering = needsClustering.slice(0, tail); // truncate empty elements + this._needsClustering = this._needsClustering.concat(needsClustering); } return this; },