0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-25 13:39:06 -05:00

optimised Grid._createActivePairsList

This commit is contained in:
liabru 2021-05-02 23:06:21 +01:00
parent 84136de6a4
commit e4b3bcd69e

View file

@ -292,23 +292,23 @@ var Common = require('../core/Common');
* @return [] pairs * @return [] pairs
*/ */
Grid._createActivePairsList = function(grid) { Grid._createActivePairsList = function(grid) {
var pairKeys, var pair,
pair, gridPairs = grid.pairs,
pairs = []; pairKeys = Common.keys(gridPairs),
pairKeysLength = pairKeys.length,
// grid.pairs is used as a hashmap pairs = [],
pairKeys = Common.keys(grid.pairs); k;
// iterate over grid.pairs // iterate over grid.pairs
for (var k = 0; k < pairKeys.length; k++) { for (k = 0; k < pairKeysLength; k++) {
pair = grid.pairs[pairKeys[k]]; pair = gridPairs[pairKeys[k]];
// if pair exists in at least one bucket // if pair exists in at least one bucket
// it is a pair that needs further collision testing so push it // it is a pair that needs further collision testing so push it
if (pair[2] > 0) { if (pair[2] > 0) {
pairs.push(pair); pairs.push(pair);
} else { } else {
delete grid.pairs[pairKeys[k]]; delete gridPairs[pairKeys[k]];
} }
} }