Skip to content

Commit 4723ef0

Browse files
committed
Removed use of Common.indexOf after some horrible perf results.
1 parent 1ae7237 commit 4723ef0

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

v3/src/physics/matter-js/lib/body/Composite.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ var Body = require('./Body');
176176
* @return {composite} The original compositeA with the composite removed
177177
*/
178178
Composite.removeComposite = function(compositeA, compositeB, deep) {
179-
var position = Common.indexOf(compositeA.composites, compositeB);
179+
// var position = Common.indexOf(compositeA.composites, compositeB);
180+
var position = compositeA.composites.indexOf(compositeB);
180181
if (position !== -1) {
181182
Composite.removeCompositeAt(compositeA, position);
182183
Composite.setModified(compositeA, true, true, false);
@@ -229,7 +230,8 @@ var Body = require('./Body');
229230
* @return {composite} The original composite with the body removed
230231
*/
231232
Composite.removeBody = function(composite, body, deep) {
232-
var position = Common.indexOf(composite.bodies, body);
233+
// var position = Common.indexOf(composite.bodies, body);
234+
var position = composite.bodies.indexOf(body);
233235
if (position !== -1) {
234236
Composite.removeBodyAt(composite, position);
235237
Composite.setModified(composite, true, true, false);
@@ -282,7 +284,8 @@ var Body = require('./Body');
282284
* @return {composite} The original composite with the constraint removed
283285
*/
284286
Composite.removeConstraint = function(composite, constraint, deep) {
285-
var position = Common.indexOf(composite.constraints, constraint);
287+
// var position = Common.indexOf(composite.constraints, constraint);
288+
var position = composite.constraints.indexOf(constraint);
286289
if (position !== -1) {
287290
Composite.removeConstraintAt(composite, position);
288291
}

v3/src/physics/matter-js/lib/collision/Grid.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ var Common = require('../core/Common');
272272
*/
273273
var _bucketRemoveBody = function(grid, bucket, body) {
274274
// remove from bucket
275-
bucket.splice(Common.indexOf(bucket, body), 1);
275+
// bucket.splice(Common.indexOf(bucket, body), 1);
276+
bucket.splice(bucket.indexOf(body), 1);
276277

277278
// update pair counts
278279
for (var i = 0; i < bucket.length; i++) {

v3/src/physics/matter-js/lib/collision/Pairs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ var Common = require('../core/Common');
9191
// deactivate previously active pairs that are now inactive
9292
for (i = 0; i < pairsList.length; i++) {
9393
pair = pairsList[i];
94-
if (pair.isActive && Common.indexOf(activePairIds, pair.id) === -1) {
94+
// if (pair.isActive && Common.indexOf(activePairIds, pair.id) === -1) {
95+
if (pair.isActive && activePairIds.indexOf(pair.id) === -1) {
9596
Pair.setActive(pair, false, timestamp);
9697
collisionEnd.push(pair);
9798
}

0 commit comments

Comments
 (0)