diff --git a/src/collision/Grid.js b/src/collision/Grid.js index 55b62ef..f7fce43 100644 --- a/src/collision/Grid.js +++ b/src/collision/Grid.js @@ -227,8 +227,13 @@ var Common = require('../core/Common'); * @param {} body */ Grid._bucketAddBody = function(grid, bucket, body) { + var gridPairs = grid.pairs, + pairId = Pair.id, + bucketLength = bucket.length, + i; + // add new pairs - for (var i = 0; i < bucket.length; i++) { + for (i = 0; i < bucketLength; i++) { var bodyB = bucket[i]; 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 // important for Grid.update to work - var pairId = Pair.id(body, bodyB), - pair = grid.pairs[pairId]; + var id = pairId(body, bodyB), + pair = gridPairs[id]; if (pair) { pair[2] += 1; } else { - grid.pairs[pairId] = [body, bodyB, 1]; + gridPairs[id] = [body, bodyB, 1]; } }