0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-26 13:49:01 -05:00

replaced "in" operator usage with access checks, it's a little faster

This commit is contained in:
liabru 2014-03-28 18:36:14 +00:00
parent 1b2d58cebf
commit 0d4a6f4000
4 changed files with 12 additions and 11 deletions

View file

@ -41,7 +41,7 @@ var Detector = {};
// find a previous collision we could reuse
var pairId = Pair.id(bodyA, bodyB),
pair = pairId in pairsTable ? pairsTable[pairId] : null,
pair = pairsTable[pairId],
previousCollision;
if (pair && pair.isActive) {
@ -100,7 +100,7 @@ var Detector = {};
// find a previous collision we could reuse
var pairId = Pair.id(bodyA, bodyB),
pair = pairId in pairsTable ? pairsTable[pairId] : null,
pair = pairsTable[pairId],
previousCollision;
if (pair && pair.isActive) {

View file

@ -56,10 +56,11 @@ var Pair = {};
if (collision.collided) {
for (var i = 0; i < supports.length; i++) {
var support = supports[i],
contactId = Contact.id(support);
contactId = Contact.id(support),
contact = contacts[contactId];
if (contactId in contacts) {
activeContacts.push(contacts[contactId]);
if (contact) {
activeContacts.push(contact);
} else {
activeContacts.push(contacts[contactId] = Contact.create(support));
}

View file

@ -56,10 +56,10 @@ var Pairs = {};
pairId = Pair.id(collision.bodyA, collision.bodyB);
activePairIds.push(pairId);
if (pairId in pairsTable) {
// pair already exists (but may or may not be active)
pair = pairsTable[pairId];
pair = pairsTable[pairId];
if (pair) {
// pair already exists (but may or may not be active)
if (pair.isActive) {
// pair exists and is active
collisionActive.push(pair);

View file

@ -67,9 +67,9 @@ var Events = {};
for (var i = 0; i < names.length; i++) {
name = names[i];
callbacks = object.events[name];
if (name in object.events) {
callbacks = object.events[name];
if (callbacks) {
eventClone = Common.clone(event, false);
eventClone.name = name;
eventClone.source = object;