Performance optimization: empty() instead of size()>0
empty() is guaranteed to be constant complexity for both vectors and lists, while size() has linear complexity for lists.
This commit is contained in:
parent
81cd33e2fa
commit
1f88d1d11b
3 changed files with 11 additions and 5 deletions
|
@ -1159,7 +1159,7 @@ void Rotor::updateDirectionsAndPositions(float *rot)
|
||||||
void Rotor::compile()
|
void Rotor::compile()
|
||||||
{
|
{
|
||||||
// Have we already been compiled?
|
// Have we already been compiled?
|
||||||
if(_rotorparts.size() != 0) return;
|
if(! _rotorparts.empty()) return;
|
||||||
|
|
||||||
//rotor is divided into _number_of_parts parts
|
//rotor is divided into _number_of_parts parts
|
||||||
//each part is calcualted at _number_of_segments points
|
//each part is calcualted at _number_of_segments points
|
||||||
|
@ -1498,7 +1498,7 @@ void Rotorgear::initRotorIteration(float *lrot,float dt)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float omegarel;
|
float omegarel;
|
||||||
if (!_rotors.size()) return;
|
if (_rotors.empty()) return;
|
||||||
Rotor* r0 = (Rotor*)_rotors.get(0);
|
Rotor* r0 = (Rotor*)_rotors.get(0);
|
||||||
omegarel= r0->getOmegaRelNeu();
|
omegarel= r0->getOmegaRelNeu();
|
||||||
for(i=0; i<_rotors.size(); i++) {
|
for(i=0; i<_rotors.size(); i++) {
|
||||||
|
@ -1514,7 +1514,7 @@ void Rotorgear::calcForces(float* torqueOut)
|
||||||
// check,<if the engine can handle the torque of the rotors.
|
// check,<if the engine can handle the torque of the rotors.
|
||||||
// If not reduce the torque to the fueselage and change rotational
|
// If not reduce the torque to the fueselage and change rotational
|
||||||
// speed of the rotors instead
|
// speed of the rotors instead
|
||||||
if (_rotors.size())
|
if (! _rotors.empty())
|
||||||
{
|
{
|
||||||
float omegarel,omegan;
|
float omegarel,omegan;
|
||||||
Rotor* r0 = (Rotor*)_rotors.get(0);
|
Rotor* r0 = (Rotor*)_rotors.get(0);
|
||||||
|
@ -1556,7 +1556,7 @@ void Rotorgear::calcForces(float* torqueOut)
|
||||||
|
|
||||||
//add the rotor brake and the gear fritcion
|
//add the rotor brake and the gear fritcion
|
||||||
float dt=0.1f;
|
float dt=0.1f;
|
||||||
if (r0->_rotorparts.size()) dt=((Rotorpart*)r0->_rotorparts.get(0))->getDt();
|
if (! r0->_rotorparts.empty()) dt=((Rotorpart*)r0->_rotorparts.get(0))->getDt();
|
||||||
|
|
||||||
float rotor_brake_torque;
|
float rotor_brake_torque;
|
||||||
rotor_brake_torque=_rotorbrake*_max_power_rotor_brake+_rotorgear_friction;
|
rotor_brake_torque=_rotorbrake*_max_power_rotor_brake+_rotorgear_friction;
|
||||||
|
|
|
@ -15,6 +15,7 @@ public:
|
||||||
void* get(int i);
|
void* get(int i);
|
||||||
void set(int i, void* p);
|
void set(int i, void* p);
|
||||||
int size();
|
int size();
|
||||||
|
bool empty();
|
||||||
private:
|
private:
|
||||||
void realloc();
|
void realloc();
|
||||||
|
|
||||||
|
@ -58,6 +59,11 @@ inline int Vector::size()
|
||||||
return _sz;
|
return _sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Vector::empty()
|
||||||
|
{
|
||||||
|
return _sz == 0;
|
||||||
|
}
|
||||||
|
|
||||||
inline void Vector::realloc()
|
inline void Vector::realloc()
|
||||||
{
|
{
|
||||||
_nelem = 2*_nelem + 1;
|
_nelem = 2*_nelem + 1;
|
||||||
|
|
|
@ -254,7 +254,7 @@ bool Wing::isMirrored()
|
||||||
void Wing::compile()
|
void Wing::compile()
|
||||||
{
|
{
|
||||||
// Have we already been compiled?
|
// Have we already been compiled?
|
||||||
if(_surfs.size() != 0) return;
|
if(! _surfs.empty()) return;
|
||||||
|
|
||||||
// Assemble the start/end coordinates of all control surfaces
|
// Assemble the start/end coordinates of all control surfaces
|
||||||
// and the wing itself into an array, sort them,
|
// and the wing itself into an array, sort them,
|
||||||
|
|
Loading…
Reference in a new issue