Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


From cppcheck: Using xxxx.empty() instead of xxxx.size() can be faster. xxxx.size() can take linear time but xxxx.empty() is guaranteed to take constant time

Sending for review.

revol_
diff --git a/basegfx/source/polygon/b2dpolypolygoncutter.cxx 
b/basegfx/source/polygon/b2dpolypolygoncutter.cxx
index 5163f1e..5f38815 100644
--- a/basegfx/source/polygon/b2dpolypolygoncutter.cxx
+++ b/basegfx/source/polygon/b2dpolypolygoncutter.cxx
@@ -933,7 +933,7 @@ namespace basegfx
             
             // first step: prepareForPolygonOperation and simple merge of non-overlapping
             // PolyPolygons for speedup; this is possible for the wanted OR-operation
-            if(aInput.size())
+            if(!aInput.empty())
             {
                 std::vector< basegfx::B2DPolyPolygon > aResult;
                 aResult.reserve(aInput.size());
@@ -942,7 +942,7 @@ namespace basegfx
                 {
                     const basegfx::B2DPolyPolygon 
aCandidate(prepareForPolygonOperation(aInput[a]));
 
-                    if(aResult.size())
+                    if(!aResult.empty())
                     {
                         const B2DRange aCandidateRange(aCandidate.getB2DRange());
                         bool bCouldMergeSimple(false);
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 91f4a88..9f64a88 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -762,7 +762,7 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter(
     }
 
     //transport seriesnames to the coordinatesystems if needed
-    if( m_aSeriesPlotterList.size() )
+    if( !m_aSeriesPlotterList.empty() )
     {
         uno::Sequence< rtl::OUString > aSeriesNames;
         bool bSeriesNamesInitialized = false;
diff --git a/chart2/source/view/main/VDataSeries.cxx b/chart2/source/view/main/VDataSeries.cxx
index 78930d9..3e896f2 100644
--- a/chart2/source/view/main/VDataSeries.cxx
+++ b/chart2/source/view/main/VDataSeries.cxx
@@ -113,7 +113,7 @@ struct lcl_LessXOfPoint
     inline bool operator() ( const std::vector< double >& first,
                              const std::vector< double >& second )
     {
-        if( first.size() > 0 && second.size() > 0 )
+        if( !first.empty() && !second.empty() )
         {
             return first[0]<second[0];
         }
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx 
b/sc/source/filter/xml/XMLStylesExportHelper.cxx
index 5ae0485..acf7b04 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.cxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.cxx
@@ -357,7 +357,7 @@ void ScMyValidationsContainer::WriteMessage(ScXMLExport& rExport,
 
 void ScMyValidationsContainer::WriteValidations(ScXMLExport& rExport)
 {
-    if (aValidationVec.size())
+    if (!aValidationVec.empty())
     {
         SvXMLElementExport aElemVs(rExport, XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATIONS, 
sal_True, sal_True);
         ScMyValidationVec::iterator aItr(aValidationVec.begin());
diff --git a/sc/source/filter/xml/xmlstyli.cxx b/sc/source/filter/xml/xmlstyli.cxx
index f4b7d6b..c4c31d8 100644
--- a/sc/source/filter/xml/xmlstyli.cxx
+++ b/sc/source/filter/xml/xmlstyli.cxx
@@ -525,7 +525,7 @@ void XMLTableStyleContext::FillPropertySet(
             sal_Int32 nNumFmt = GetNumberFormat();
             if (nNumFmt >= 0)
                 AddProperty(CTF_SC_NUMBERFORMAT, uno::makeAny(nNumFmt));
-            if (!bConditionalFormatCreated && (aMaps.size() > 0))
+            if (!bConditionalFormatCreated && (!aMaps.empty()))
             {
                 aConditionalFormat = 
rPropSet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CONDXML)));
                 std::vector<ScXMLMapContent>::iterator aItr(aMaps.begin());
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index 1895c78..c0d3387 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -1159,7 +1159,7 @@ bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* 
pDocSh, S
         vNames.push_back( aToken );
     } while ( nIndex >= 0 );
 
-    if ( !vNames.size() )
+    if ( vNames.empty() )
         vNames.push_back( sName );
 
     std::vector< rtl::OUString >::iterator it = vNames.begin();
diff --git a/binfilter/bf_sc/source/filter/xml/sc_XMLStylesExportHelper.cxx 
b/binfilter/bf_sc/source/filter/xml/sc_XMLStylesExportHelper.cxx
index ef6d3b3..6557973 100644
--- a/binfilter/bf_sc/source/filter/xml/sc_XMLStylesExportHelper.cxx
+++ b/binfilter/bf_sc/source/filter/xml/sc_XMLStylesExportHelper.cxx
@@ -344,7 +344,7 @@ void ScMyValidationsContainer::WriteMessage(ScXMLExport& rExport,
 
 void ScMyValidationsContainer::WriteValidations(ScXMLExport& rExport)
 {
-    if (aValidationVec.size())
+    if (!aValidationVec.empty())
     {
         SvXMLElementExport aElemVs(rExport, XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATIONS, 
sal_True, sal_True);
         ScMyValidationVec::iterator aItr = aValidationVec.begin();
diff --git a/binfilter/bf_sc/source/filter/xml/sc_xmlexprt.cxx 
b/binfilter/bf_sc/source/filter/xml/sc_xmlexprt.cxx
index 18a89df..62fa91b 100644
--- a/binfilter/bf_sc/source/filter/xml/sc_xmlexprt.cxx
+++ b/binfilter/bf_sc/source/filter/xml/sc_xmlexprt.cxx
@@ -1501,7 +1501,7 @@ void ScXMLExport::_ExportAutoStyles()
                             if (xTableProperties.is())
                             {
                                 std::vector<XMLPropertyState> xPropStates = 
xTableStylesExportPropertySetMapper->Filter(xTableProperties);
-                                if(xPropStates.size())
+                                if(!xPropStates.empty())
                                 {
                                     ::rtl::OUString sParent;
                                     ::rtl::OUString sName;
@@ -1587,7 +1587,7 @@ void ScXMLExport::_ExportAutoStyles()
                                                 }
                                                 if (sStyleName.getLength())
                                                 {
-                                                    if (xPropStates.size())
+                                                    if (!xPropStates.empty())
                                                     {
                                                         sal_Int32 nIndex;
                                                         ::rtl::OUString sName;
@@ -1674,7 +1674,7 @@ void ScXMLExport::_ExportAutoStyles()
                                                 if (xColumnProperties.is())
                                                 {
                                                     std::vector<XMLPropertyState> xPropStates = 
xColumnStylesExportPropertySetMapper->Filter(xColumnProperties);
-                                                    if(xPropStates.size())
+                                                    if(!xPropStates.empty())
                                                     {
                                                         std::vector< XMLPropertyState >::iterator 
aItr = xPropStates.begin();
                                                         while (aItr != xPropStates.end())
@@ -1739,7 +1739,7 @@ void ScXMLExport::_ExportAutoStyles()
                                                 if(xRowProperties.is())
                                                 {
                                                     std::vector<XMLPropertyState> xPropStates = 
xRowStylesExportPropertySetMapper->Filter(xRowProperties);
-                                                    if(xPropStates.size())
+                                                    if(!xPropStates.empty())
                                                     {
                                                         ::rtl::OUString sParent;
                                                         ::rtl::OUString sName;
diff --git a/binfilter/bf_sc/source/filter/xml/sc_xmlstyli.cxx 
b/binfilter/bf_sc/source/filter/xml/sc_xmlstyli.cxx
index ec3f438..405f4f2 100644
--- a/binfilter/bf_sc/source/filter/xml/sc_xmlstyli.cxx
+++ b/binfilter/bf_sc/source/filter/xml/sc_xmlstyli.cxx
@@ -554,7 +554,7 @@ void XMLTableStyleContext::FillPropertySet(
                     AddProperty(CTF_SC_NUMBERFORMAT, aNumberFormat);
                 }
             }
-            if (!bConditionalFormatCreated && (aMaps.size() > 0))
+            if (!bConditionalFormatCreated && (!aMaps.empty()))
             {
                 aConditionalFormat = 
rPropSet->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_CONDITIONALFORMAT)));
                 std::vector<ScXMLMapContent>::iterator aItr = aMaps.begin();
diff --git a/binfilter/bf_svtools/source/items1/svt_stylepool.cxx 
b/binfilter/bf_svtools/source/items1/svt_stylepool.cxx
index 83e4ea3..5ff3979 100644
--- a/binfilter/bf_svtools/source/items1/svt_stylepool.cxx
+++ b/binfilter/bf_svtools/source/items1/svt_stylepool.cxx
@@ -57,7 +57,7 @@ namespace binfilter
         Node( const SfxPoolItem& rItem, Node* pParent ) : // child node Ctor
             pItem( rItem.Clone() ), pUpper( pParent ){}
         ~Node();
-        bool hasItemSet() const { return 0 < aItemSet.size(); }
+        bool hasItemSet() const { return 0 < !aItemSet.empty(); }
         const StylePool::SfxItemSet_Pointer_t getItemSet() const { return 
aItemSet[aItemSet.size()-1]; }
         void setItemSet( const SfxItemSet& rSet ){ aItemSet.push_back( 
StylePool::SfxItemSet_Pointer_t( rSet.Clone() ) ); }
         Node* findChildNode( const SfxPoolItem& rItem );
diff --git a/binfilter/bf_svtools/source/uno/svt_unoimap.cxx 
b/binfilter/bf_svtools/source/uno/svt_unoimap.cxx
index 86d462c..bc7a70d 100644
--- a/binfilter/bf_svtools/source/uno/svt_unoimap.cxx
+++ b/binfilter/bf_svtools/source/uno/svt_unoimap.cxx
@@ -733,7 +733,7 @@ Type SAL_CALL SvUnoImageMap::getElementType(  ) throw(RuntimeException)
 
 sal_Bool SAL_CALL SvUnoImageMap::hasElements(  ) throw(RuntimeException)
 {
-    return maObjectList.size() != 0;
+    return (!maObjectList.empty());
 }
 
 // XSerivceInfo
diff --git a/binfilter/bf_xmloff/source/chart/xmloff_SchXMLExport.cxx 
b/binfilter/bf_xmloff/source/chart/xmloff_SchXMLExport.cxx
index 1342aaa..d2933f4 100644
--- a/binfilter/bf_xmloff/source/chart/xmloff_SchXMLExport.cxx
+++ b/binfilter/bf_xmloff/source/chart/xmloff_SchXMLExport.cxx
@@ -1138,7 +1138,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
 
             // write style name
 //            AddAutoStyleAttribute( aPropertyStates );   // can't be used here because we need 
the name
-            if( aPropertyStates.size())
+            if( !aPropertyStates.empty())
             {
                 DBG_ASSERT( ! maAutoStyleNameQueue.empty(), "Autostyle queue empty!" );
                 if( maAutoStyleNameQueue.empty())
@@ -1273,7 +1273,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
             {
                 aPropertyStates = mxExpPropMapper->Filter( xStatProp );
 
-                if( aPropertyStates.size() > 0 )
+                if( !aPropertyStates.empty() )
                 {
                     // write element
                     if( bExportContent )
@@ -1303,7 +1303,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
             {
                 aPropertyStates = mxExpPropMapper->Filter( xStatProp );
 
-                if( aPropertyStates.size() > 0 )
+                if( !aPropertyStates.empty() )
                 {
                     // write element
                     if( bExportContent )
@@ -1377,7 +1377,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
                     if( xPropSet.is())
                     {
                         aPropertyStates = mxExpPropMapper->Filter( xPropSet );
-                        if( aPropertyStates.size() > 0 )
+                        if( !aPropertyStates.empty() )
                         {
                             // write data-point with style
                             DBG_ASSERT( ! maAutoStyleNameQueue.empty(), "Autostyle queue empty!" );
@@ -1469,7 +1469,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
                     if( xPropSet.is())
                     {
                         aPropertyStates = mxExpPropMapper->Filter( xPropSet );
-                        if( aPropertyStates.size() > 0 )
+                        if( !aPropertyStates.empty() )
                             CollectAutoStyle( aPropertyStates );
                     }
                 }
@@ -1495,7 +1495,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
                 aPropertyStates.clear();
                 aPropertyStates = mxExpPropMapper->Filter( xStockPropSet );
 
-                if( aPropertyStates.size() > 0 )
+                if( !aPropertyStates.empty() )
                 {
                     if( bExportContent )
                     {
@@ -1517,7 +1517,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
                 aPropertyStates.clear();
                 aPropertyStates = mxExpPropMapper->Filter( xStockPropSet );
 
-                if( aPropertyStates.size() > 0 )
+                if( !aPropertyStates.empty() )
                 {
                     if( bExportContent )
                     {
@@ -1539,7 +1539,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
                 aPropertyStates.clear();
                 aPropertyStates = mxExpPropMapper->Filter( xStockPropSet );
 
-                if( aPropertyStates.size() > 0 )
+                if( !aPropertyStates.empty() )
                 {
                     if( bExportContent )
                     {
@@ -1571,7 +1571,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
         {
             aPropertyStates = mxExpPropMapper->Filter( xWallPropSet );
 
-            if( aPropertyStates.size() > 0 )
+            if( !aPropertyStates.size() )
             {
                 // write element
                 if( bExportContent )
@@ -1599,7 +1599,7 @@ void SchXMLExportHelper::exportPlotArea( uno::Reference< chart::XDiagram > 
xDiag
         {
             aPropertyStates = mxExpPropMapper->Filter( xFloorPropSet );
 
-            if( aPropertyStates.size() > 0 )
+            if( !aPropertyStates.size() )
             {
                 // write element
                 if( bExportContent )
diff --git a/binfilter/bf_xmloff/source/style/xmloff_xmlexppr.cxx 
b/binfilter/bf_xmloff/source/style/xmloff_xmlexppr.cxx
index 893dfc7..8baea30 100644
--- a/binfilter/bf_xmloff/source/style/xmloff_xmlexppr.cxx
+++ b/binfilter/bf_xmloff/source/style/xmloff_xmlexppr.cxx
@@ -618,7 +618,7 @@ vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter(
     }
 
     // Call centext-filter
-    if( aPropStateArray.size() > 0 )
+    if( !aPropStateArray.empty() )
         ContextFilter( aPropStateArray, xPropSet );
 
     // Have to do if we change from a vector to a list or something like that
diff --git a/binfilter/bf_xmloff/source/text/xmloff_txtflde.cxx 
b/binfilter/bf_xmloff/source/text/xmloff_txtflde.cxx
index 97d37ce..6bcce1a 100644
--- a/binfilter/bf_xmloff/source/text/xmloff_txtflde.cxx
+++ b/binfilter/bf_xmloff/source/text/xmloff_txtflde.cxx
@@ -1841,7 +1841,7 @@ void XMLTextFieldExport::ExportFieldDeclarations(
     // now process fields:
 
     // variable field masters:
-    if (aVarName.size() > 0)
+    if (!aVarName.empty())
     {
         SvXMLElementExport aElem( GetExport(),
                                   XML_NAMESPACE_TEXT,
@@ -1900,7 +1900,7 @@ void XMLTextFieldExport::ExportFieldDeclarations(
     // else: no declarations element
 
     // sequence field masters:
-    if (aSeqName.size() > 0)
+    if (!aSeqName.empty())
     {
         SvXMLElementExport aElem( GetExport(),
                                   XML_NAMESPACE_TEXT,
@@ -1942,7 +1942,7 @@ void XMLTextFieldExport::ExportFieldDeclarations(
     // else: no declarations element
 
     // user field field masters:
-    if (aUserName.size() > 0)
+    if (!aUserName.empty())
     {
         SvXMLElementExport aElem( GetExport(),
                                   XML_NAMESPACE_TEXT,
@@ -1991,7 +1991,7 @@ void XMLTextFieldExport::ExportFieldDeclarations(
     // else: no declarations element
 
     // DDE field field masters:
-    if (aDdeName.size() > 0)
+    if (!aDdeName.empty())
     {
         SvXMLElementExport aElem( GetExport(),
                                   XML_NAMESPACE_TEXT,
diff --git a/binfilter/bf_xmloff/source/text/xmloff_txtparae.cxx 
b/binfilter/bf_xmloff/source/text/xmloff_txtparae.cxx
index eb422ea..c91390b 100644
--- a/binfilter/bf_xmloff/source/text/xmloff_txtparae.cxx
+++ b/binfilter/bf_xmloff/source/text/xmloff_txtparae.cxx
@@ -199,7 +199,7 @@ void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
         }
     }
 
-    if( xPropStates.size() > 0L )
+    if( !xPropStates.empty() )
     {
         Reference< XPropertySetInfo > xPropSetInfo =
             rPropSet->getPropertySetInfo();
@@ -324,7 +324,7 @@ void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
         }
     }
 
-    if( xPropStates.size() > 0L )
+    if( !xPropStates.empty() )
     {
         OUString sParent, sCondParent;
         Any aAny;
@@ -379,7 +379,7 @@ void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
             }
             break;
         }
-        if( xPropStates.size() > 0 )
+        if( !xPropStates.empty() )
         {
             GetAutoStylePool().Add( nFamily, sParent, xPropStates );
             if( sCondParent.getLength() && sParent != sCondParent )
@@ -425,7 +425,7 @@ OUString XMLTextParagraphExport::Find(
         }
     }
 
-    if( xPropStates.size() > 0L )
+    if( !xPropStates.empty() )
         sName = GetAutoStylePool().Find( nFamily, sName, xPropStates );
 
     return sName;
diff --git a/basic/source/uno/dlgcont.cxx b/basic/source/uno/dlgcont.cxx
index c8da150..f81a878 100644
--- a/basic/source/uno/dlgcont.cxx
+++ b/basic/source/uno/dlgcont.cxx
@@ -316,7 +316,7 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e
                     ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, 
mxOwnerDocument );
                     std::vector< rtl::OUString > vEmbeddedImageURLs;
                     lcl_deepInspectForEmbeddedImages( Reference< XInterface >( xDialogModel, 
UNO_QUERY ),  vEmbeddedImageURLs );
-                    if ( vEmbeddedImageURLs.size() )
+                    if ( !vEmbeddedImageURLs.empty() )
                     {
                         // Export the images to the storage
                         Sequence< Any > aArgs( 1 );

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.