From 96d9e5408054e463ba2bc22269cf655c696018e2 Mon Sep 17 00:00:00 2001 From: donggas90 Date: Mon, 8 Jun 2015 13:35:17 +0900 Subject: [PATCH 1/2] Improve Compound Shape Construction. --- src/BulletCollision/CollisionShapes/btCompoundShape.cpp | 4 +++- src/BulletCollision/CollisionShapes/btCompoundShape.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp index 8842fa2f1..e8c8c336c 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp @@ -18,7 +18,7 @@ subject to the following restrictions: #include "BulletCollision/BroadphaseCollision/btDbvt.h" #include "LinearMath/btSerializer.h" -btCompoundShape::btCompoundShape(bool enableDynamicAabbTree) +btCompoundShape::btCompoundShape(bool enableDynamicAabbTree, const int initialChildCapacity) : m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)), m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)), m_dynamicAabbTree(0), @@ -34,6 +34,8 @@ m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)) m_dynamicAabbTree = new(mem) btDbvt(); btAssert(mem==m_dynamicAabbTree); } + + m_children.reserve(initialChildCapacity); } diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.h b/src/BulletCollision/CollisionShapes/btCompoundShape.h index 141034a8e..ce3dfa2fe 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.h +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.h @@ -70,7 +70,7 @@ protected: public: BT_DECLARE_ALIGNED_ALLOCATOR(); - btCompoundShape(bool enableDynamicAabbTree = true); + explicit btCompoundShape(bool enableDynamicAabbTree = true, const int initialChildCapacity = 0); virtual ~btCompoundShape(); From a3b41fdcb9427c4adec41afb557d46731e5ed820 Mon Sep 17 00:00:00 2001 From: donggas90 Date: Mon, 8 Jun 2015 13:40:23 +0900 Subject: [PATCH 2/2] Simple Improve Array --- src/LinearMath/btAlignedObjectArray.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/LinearMath/btAlignedObjectArray.h b/src/LinearMath/btAlignedObjectArray.h index 24e59ab65..db1864803 100644 --- a/src/LinearMath/btAlignedObjectArray.h +++ b/src/LinearMath/btAlignedObjectArray.h @@ -202,24 +202,16 @@ protected: ///when the new number of elements is smaller, the destructor will be called, but memory will not be freed, to reduce performance overhead of run-time memory (de)allocations. SIMD_FORCE_INLINE void resizeNoInitialize(int newsize) { - int curSize = size(); - - if (newsize < curSize) + if (newsize > size()) { - } else - { - if (newsize > size()) - { - reserve(newsize); - } - //leave this uninitialized + reserve(newsize); } m_size = newsize; } SIMD_FORCE_INLINE void resize(int newsize, const T& fillData=T()) { - int curSize = size(); + const register int curSize = size(); if (newsize < curSize) { @@ -229,7 +221,7 @@ protected: } } else { - if (newsize > size()) + if (newsize > curSize) { reserve(newsize); } @@ -246,7 +238,7 @@ protected: } SIMD_FORCE_INLINE T& expandNonInitializing( ) { - int sz = size(); + const register int sz = size(); if( sz == capacity() ) { reserve( allocSize(size()) ); @@ -259,7 +251,7 @@ protected: SIMD_FORCE_INLINE T& expand( const T& fillValue=T()) { - int sz = size(); + const register int sz = size(); if( sz == capacity() ) { reserve( allocSize(size()) ); @@ -275,7 +267,7 @@ protected: SIMD_FORCE_INLINE void push_back(const T& _Val) { - int sz = size(); + const register int sz = size(); if( sz == capacity() ) { reserve( allocSize(size()) );