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
ee403fd83a
commit
15e3e92ec2
@ -629,7 +629,7 @@ bool SGMetar::scanWeather()
|
||||
weather = pre + weather + post;
|
||||
weather.erase(weather.length() - 1);
|
||||
_weather.push_back(weather);
|
||||
if( w.phenomena.size() > 0 )
|
||||
if( ! w.phenomena.empty() )
|
||||
_weather2.push_back( w );
|
||||
_grpcount++;
|
||||
return true;
|
||||
|
@ -934,7 +934,7 @@ bool SGBinObject::write_ascii( const string& base, const string& name,
|
||||
fprintf(fp, "\n");
|
||||
|
||||
// dump individual triangles if they exist
|
||||
if ( tris_v.size() > 0 ) {
|
||||
if ( ! tris_v.empty() ) {
|
||||
fprintf(fp, "# triangle groups\n");
|
||||
|
||||
int start = 0;
|
||||
@ -982,7 +982,7 @@ bool SGBinObject::write_ascii( const string& base, const string& name,
|
||||
}
|
||||
|
||||
// dump triangle groups
|
||||
if ( strips_v.size() > 0 ) {
|
||||
if ( ! strips_v.empty() ) {
|
||||
fprintf(fp, "# triangle strips\n");
|
||||
|
||||
int start = 0;
|
||||
|
@ -144,7 +144,7 @@ void SGPath::set_cached(bool cached)
|
||||
|
||||
// append another piece to the existing path
|
||||
void SGPath::append( const string& p ) {
|
||||
if ( path.size() == 0 ) {
|
||||
if ( path.empty() ) {
|
||||
path = p;
|
||||
} else {
|
||||
if ( p[0] != sgDirPathSep ) {
|
||||
@ -173,7 +173,7 @@ void SGPath::add( const string& p ) {
|
||||
// concatenate a string to the end of the path without inserting a
|
||||
// path separator
|
||||
void SGPath::concat( const string& p ) {
|
||||
if ( path.size() == 0 ) {
|
||||
if ( path.empty() ) {
|
||||
path = p;
|
||||
} else {
|
||||
path += p;
|
||||
@ -378,7 +378,7 @@ int SGPath::create_dir( mode_t mode ) {
|
||||
string_list sgPathBranchSplit( const string &dirpath ) {
|
||||
string_list path_elements;
|
||||
string element, path = dirpath;
|
||||
while ( path.size() ) {
|
||||
while ( ! path.empty() ) {
|
||||
size_t p = path.find( sgDirPathSep );
|
||||
if ( p != string::npos ) {
|
||||
element = path.substr( 0, p );
|
||||
@ -387,7 +387,7 @@ string_list sgPathBranchSplit( const string &dirpath ) {
|
||||
element = path;
|
||||
path = "";
|
||||
}
|
||||
if ( element.size() )
|
||||
if ( ! element.empty() )
|
||||
path_elements.push_back( element );
|
||||
}
|
||||
return path_elements;
|
||||
|
@ -37,11 +37,11 @@ public:
|
||||
virtual ~TiedPropertyList()
|
||||
{
|
||||
_root = 0;
|
||||
if (size()>0)
|
||||
if (! empty())
|
||||
{
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Detected properties with dangling ties. Use 'Untie' before removing a TiedPropertyList.");
|
||||
// running debug mode: go, fix it!
|
||||
assert(size() == 0);
|
||||
assert(empty());
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ public:
|
||||
}
|
||||
|
||||
void Untie() {
|
||||
while( size() > 0 ) {
|
||||
while( ! empty() ) {
|
||||
SG_LOG( SG_GENERAL, SG_DEBUG, "untie of " << back()->getPath() );
|
||||
back()->untie();
|
||||
pop_back();
|
||||
|
@ -316,7 +316,7 @@ getVectorProperties(const SGPropertyNode* prop,
|
||||
PropertyList useProps = prop->getChildren("use");
|
||||
if (useProps.size() == 1) {
|
||||
string parentName = useProps[0]->getStringValue();
|
||||
if (parentName.size() == 0 || parentName[0] != '/')
|
||||
if (parentName.empty() || parentName[0] != '/')
|
||||
parentName = options->getPropertyNode()->getPath() + "/" + parentName;
|
||||
if (parentName[parentName.size() - 1] != '/')
|
||||
parentName.append("/");
|
||||
@ -331,7 +331,7 @@ getVectorProperties(const SGPropertyNode* prop,
|
||||
itr != end;
|
||||
++itr) {
|
||||
string childName = (*itr)->getStringValue();
|
||||
if (childName.size() == 0 || childName[0] != '/')
|
||||
if (childName.empty() || childName[0] != '/')
|
||||
result.push_back(parentName + childName);
|
||||
else
|
||||
result.push_back(childName);
|
||||
|
@ -167,12 +167,12 @@ Technique::processDrawables(const EffectGeode::DrawablesIterator& begin,
|
||||
BOOST_FOREACH(ref_ptr<Pass>& pass, passes)
|
||||
{
|
||||
osg::ref_ptr<osg::StateSet> ss = pass;
|
||||
if (ecv && ( pass->getBufferUnitList().size() != 0 || pass->getPositionedUniformMap().size() != 0 ) ) {
|
||||
if (ecv && ( ! pass->getBufferUnitList().empty() || ! pass->getPositionedUniformMap().empty() ) ) {
|
||||
ss = static_cast<osg::StateSet*>(
|
||||
pass->clone( osg::CopyOp( ( pass->getBufferUnitList().size() != 0 ?
|
||||
pass->clone( osg::CopyOp( ( ! pass->getBufferUnitList().empty() ?
|
||||
osg::CopyOp::DEEP_COPY_TEXTURES :
|
||||
osg::CopyOp::SHALLOW_COPY ) |
|
||||
( pass->getPositionedUniformMap().size() != 0 ?
|
||||
( ! pass->getPositionedUniformMap().empty() ?
|
||||
osg::CopyOp::DEEP_COPY_UNIFORMS :
|
||||
osg::CopyOp::SHALLOW_COPY ) )
|
||||
)
|
||||
|
@ -202,7 +202,7 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
|
||||
}
|
||||
}
|
||||
|
||||
if (textures.size() == 0 && texturesets.size() == 0) {
|
||||
if (textures.empty() && texturesets.empty()) {
|
||||
SGPath tpath("Textures");
|
||||
tpath.append("Terrain");
|
||||
tpath.append("unknown.rgb");
|
||||
@ -455,7 +455,7 @@ Effect* SGMaterial::get_effect(int i)
|
||||
|
||||
Effect* SGMaterial::get_effect(const SGTexturedTriangleBin& triangleBin)
|
||||
{
|
||||
if (_status.size() == 0) {
|
||||
if (_status.empty()) {
|
||||
SG_LOG( SG_GENERAL, SG_WARN, "No effect available.");
|
||||
return 0;
|
||||
}
|
||||
@ -472,7 +472,7 @@ Effect* SGMaterial::get_effect()
|
||||
|
||||
osg::Texture2D* SGMaterial::get_object_mask(const SGTexturedTriangleBin& triangleBin)
|
||||
{
|
||||
if (_status.size() == 0) {
|
||||
if (_status.empty()) {
|
||||
SG_LOG( SG_GENERAL, SG_WARN, "No mask available.");
|
||||
return 0;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
numeric( aNumeric ),
|
||||
format( aFormat )
|
||||
{
|
||||
if( format.size() == 0 ) {
|
||||
if( format.empty() ) {
|
||||
if( numeric ) format = "%f";
|
||||
else format = "%s";
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace simgear
|
||||
{
|
||||
void CloudShaderGeometry::drawImplementation(RenderInfo& renderInfo) const
|
||||
{
|
||||
if (!_cloudsprites.size()) return;
|
||||
if (_cloudsprites.empty()) return;
|
||||
|
||||
osg::State& state = *renderInfo.getState();
|
||||
|
||||
|
@ -395,7 +395,7 @@ bool SGCloudField::repositionCloud(int identifier, float lon, float lat, float a
|
||||
}
|
||||
|
||||
bool SGCloudField::isDefined3D(void) {
|
||||
return (cloud_hash.size() > 0);
|
||||
return (! cloud_hash.empty());
|
||||
}
|
||||
|
||||
SGCloudField::CloudFog::CloudFog() {
|
||||
|
@ -429,7 +429,7 @@ void AirportSignBuilder::addSign(const SGGeod& pos, double heading, const std::s
|
||||
}
|
||||
}
|
||||
|
||||
if (newmat.size()) {
|
||||
if (! newmat.empty()) {
|
||||
material = d->materials->find(newmat);
|
||||
newmat.clear();
|
||||
}
|
||||
|
@ -1015,7 +1015,7 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
|
||||
randomObjects->setName("Random objects");
|
||||
}
|
||||
|
||||
if (tileGeometryBin.randomBuildings.size() > 0) {
|
||||
if (! tileGeometryBin.randomBuildings.empty()) {
|
||||
buildingNode = createRandomBuildings(tileGeometryBin.randomBuildings, osg::Matrix::identity(),
|
||||
options);
|
||||
buildingNode->setName("Random buildings");
|
||||
@ -1025,7 +1025,7 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
|
||||
// Now add some random forest.
|
||||
tileGeometryBin.computeRandomForest(matlib, vegetation_density);
|
||||
|
||||
if (tileGeometryBin.randomForest.size() > 0) {
|
||||
if (! tileGeometryBin.randomForest.empty()) {
|
||||
forestNode = createForest(tileGeometryBin.randomForest, osg::Matrix::identity(),
|
||||
options);
|
||||
forestNode->setName("Random trees");
|
||||
|
Loading…
Reference in New Issue
Block a user