# UNDF: UNDF-2026-000000961 --- a/cocos/physics/CCPhysicsWorld.h +++ b/cocos/physics/CCPhysicsWorld.h @@ -33,6 +33,7 @@ #include #include +#include struct cpSpace; @@ -230,6 +231,7 @@ std::vector _joints; + std::unordered_set _jointsSet; // O(1) membership mirror of _joints std::vector _delayAddJoints; --- a/cocos/physics/CCPhysicsWorld.cpp +++ b/cocos/physics/CCPhysicsWorld.cpp @@ -310,7 +310,7 @@ bool PhysicsWorld::collisionBeginCallback(PhysicsContact& contact) // check the joint is collision enable or not for (PhysicsJoint* joint : jointsA) { - if (std::find(_joints.begin(), _joints.end(), joint) == _joints.end()) + if (_jointsSet.find(joint) == _jointsSet.end()) { continue; } @@ -688,6 +688,7 @@ void PhysicsWorld::updateJoints() if (joint->initJoint()) { _joints.push_back(joint); + _jointsSet.insert(joint); } else { // Also update doRemoveJoint to maintain _jointsSet: // When removing from _joints, also call _jointsSet.erase(joint).