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:
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
|
||||
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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -55,11 +55,11 @@ var Pairs = {};
|
|||
if (collision.collided) {
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue