0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

optimised Grid._bucketAddBody

This commit is contained in:
liabru 2021-05-02 23:05:21 +01:00
parent 0af144c78b
commit 5e3c629b90

View file

@ -227,8 +227,13 @@ var Common = require('../core/Common');
* @param {} body * @param {} body
*/ */
Grid._bucketAddBody = function(grid, bucket, body) { Grid._bucketAddBody = function(grid, bucket, body) {
var gridPairs = grid.pairs,
pairId = Pair.id,
bucketLength = bucket.length,
i;
// add new pairs // add new pairs
for (var i = 0; i < bucket.length; i++) { for (i = 0; i < bucketLength; i++) {
var bodyB = bucket[i]; var bodyB = bucket[i];
if (body.id === bodyB.id || (body.isStatic && bodyB.isStatic)) if (body.id === bodyB.id || (body.isStatic && bodyB.isStatic))
@ -236,13 +241,13 @@ var Common = require('../core/Common');
// keep track of the number of buckets the pair exists in // keep track of the number of buckets the pair exists in
// important for Grid.update to work // important for Grid.update to work
var pairId = Pair.id(body, bodyB), var id = pairId(body, bodyB),
pair = grid.pairs[pairId]; pair = gridPairs[id];
if (pair) { if (pair) {
pair[2] += 1; pair[2] += 1;
} else { } else {
grid.pairs[pairId] = [body, bodyB, 1]; gridPairs[id] = [body, bodyB, 1];
} }
} }