mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-27 13:59:01 -05:00
replaced "in" operator usage with access checks, it's a little faster
This commit is contained in:
parent
1b2d58cebf
commit
0d4a6f4000
4 changed files with 12 additions and 11 deletions
|
@ -41,7 +41,7 @@ var Detector = {};
|
||||||
|
|
||||||
// find a previous collision we could reuse
|
// find a previous collision we could reuse
|
||||||
var pairId = Pair.id(bodyA, bodyB),
|
var pairId = Pair.id(bodyA, bodyB),
|
||||||
pair = pairId in pairsTable ? pairsTable[pairId] : null,
|
pair = pairsTable[pairId],
|
||||||
previousCollision;
|
previousCollision;
|
||||||
|
|
||||||
if (pair && pair.isActive) {
|
if (pair && pair.isActive) {
|
||||||
|
@ -100,7 +100,7 @@ var Detector = {};
|
||||||
|
|
||||||
// find a previous collision we could reuse
|
// find a previous collision we could reuse
|
||||||
var pairId = Pair.id(bodyA, bodyB),
|
var pairId = Pair.id(bodyA, bodyB),
|
||||||
pair = pairId in pairsTable ? pairsTable[pairId] : null,
|
pair = pairsTable[pairId],
|
||||||
previousCollision;
|
previousCollision;
|
||||||
|
|
||||||
if (pair && pair.isActive) {
|
if (pair && pair.isActive) {
|
||||||
|
|
|
@ -56,10 +56,11 @@ var Pair = {};
|
||||||
if (collision.collided) {
|
if (collision.collided) {
|
||||||
for (var i = 0; i < supports.length; i++) {
|
for (var i = 0; i < supports.length; i++) {
|
||||||
var support = supports[i],
|
var support = supports[i],
|
||||||
contactId = Contact.id(support);
|
contactId = Contact.id(support),
|
||||||
|
contact = contacts[contactId];
|
||||||
|
|
||||||
if (contactId in contacts) {
|
if (contact) {
|
||||||
activeContacts.push(contacts[contactId]);
|
activeContacts.push(contact);
|
||||||
} else {
|
} else {
|
||||||
activeContacts.push(contacts[contactId] = Contact.create(support));
|
activeContacts.push(contacts[contactId] = Contact.create(support));
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,10 +56,10 @@ var Pairs = {};
|
||||||
pairId = Pair.id(collision.bodyA, collision.bodyB);
|
pairId = Pair.id(collision.bodyA, collision.bodyB);
|
||||||
activePairIds.push(pairId);
|
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) {
|
if (pair.isActive) {
|
||||||
// pair exists and is active
|
// pair exists and is active
|
||||||
collisionActive.push(pair);
|
collisionActive.push(pair);
|
||||||
|
|
|
@ -67,9 +67,9 @@ var Events = {};
|
||||||
|
|
||||||
for (var i = 0; i < names.length; i++) {
|
for (var i = 0; i < names.length; i++) {
|
||||||
name = names[i];
|
name = names[i];
|
||||||
|
|
||||||
if (name in object.events) {
|
|
||||||
callbacks = object.events[name];
|
callbacks = object.events[name];
|
||||||
|
|
||||||
|
if (callbacks) {
|
||||||
eventClone = Common.clone(event, false);
|
eventClone = Common.clone(event, false);
|
||||||
eventClone.name = name;
|
eventClone.name = name;
|
||||||
eventClone.source = object;
|
eventClone.source = object;
|
||||||
|
|
Loading…
Reference in a new issue