Patch #3205 2011-08-30 13:24

xazax-hun

Minor cleanups and optimizations
Download
3205-Minor_cleanups.patch (33.6 KB)
Category
Application::Refinement
Status
Open
Close date
 
Assigned to
tpetrov
Index: plugins/astyle/astyle/ASBeautifier.cpp
===================================================================
--- plugins/astyle/astyle/ASBeautifier.cpp    (revision 7439)
+++ plugins/astyle/astyle/ASBeautifier.cpp    (working copy)
@@ -774,7 +774,7 @@
         if (backslashEndsPrevLine)  // must continue to clear variables
             line = ' ';
         else if (emptyLineFill && !isInQuoteContinuation
-                 && (headerStack->size() > 0 || isInEnum))
+                 && (!headerStack->empty() || isInEnum))
             return preLineWS(prevFinalLineSpaceTabCount, prevFinalLineTabCount);
         else
             return line;
@@ -900,7 +900,7 @@
     // Flag an indented header in case this line is a one-line block.
     // The header in the header stack will be deleted by a one-line block.
     bool isInExtraHeaderIndent = false;
-    if (headerStack->size() > 0
+    if (!headerStack->empty()
             && line.length() > 0
             && line[0] == '{'
             && (headerStack->back() != &AS_OPEN_BRACKET
@@ -977,7 +977,7 @@
              && line.length() > 0
              && lineOpeningBlocksNum == 0
              && lineOpeningBlocksNum == lineClosingBlocksNum
-             && (headerStack->size() > 0 && headerStack->back() == &AS_CLASS))
+             && (!headerStack->empty() && headerStack->back() == &AS_CLASS))
         --tabCount;
 
     if (tabCount < 0)
@@ -1354,7 +1354,7 @@
     if (container != NULL)
     {
         vector<vector<const string*>*>::iterator iter = container->begin();
-        for (; iter != container->end(); iter++)
+        for (; iter != container->end(); ++iter)
             delete *iter;
         container->clear();
         delete (container);
@@ -1962,7 +1962,7 @@
                 // if have a struct header, this is a declaration not a definition
                 if (ch == '('
                         && (isInClassInitializer || isInClassHeaderTab)
-                        && headerStack->size() > 0
+                        && !headerStack->empty()
                         && headerStack->back() == &AS_STRUCT)
                 {
                     headerStack->pop_back();
@@ -2051,7 +2051,7 @@
             // remove inStatementIndent for C++ class initializer
             if (isInClassInitializer)
             {
-                if (inStatementIndentStack->size() > 0)
+                if (!inStatementIndentStack->empty())
                     inStatementIndentStack->pop_back();
                 isInStatement = false;
                 if (lineBeginsWithBracket)
@@ -2097,7 +2097,7 @@
                 {
                     tabCount -= classInitializerTabs;
                     // decrease one more if an empty class
-                    if (headerStack->size() > 0
+                    if (!headerStack->empty()
                             && (*headerStack).back() == &AS_CLASS)
                     {
                         int nextChar = getNextProgramCharDistance(line, i);
@@ -2107,7 +2107,7 @@
                 }
             }
 
-            if (bracketIndent && !namespaceIndent && headerStack->size() > 0
+            if (bracketIndent && !namespaceIndent && !headerStack->empty()
                     && (*headerStack).back() == &AS_NAMESPACE)
             {
                 shouldIndentBrackettedLine = false;
@@ -2115,7 +2115,7 @@
             }
 
             // an indentable struct is treated like a class in the header stack
-            if (headerStack->size() > 0
+            if (!headerStack->empty()
                     && (*headerStack).back() == &AS_STRUCT
                     && isInIndentableStruct)
                 (*headerStack).back() = &AS_CLASS;
@@ -2124,7 +2124,7 @@
             blockStatementStack->push_back(isInStatement);
 
             inStatementIndentStackSizeStack->push_back(inStatementIndentStack->size());
-            if (inStatementIndentStack->size() > 0)
+            if (!inStatementIndentStack->empty())
             {
                 spaceTabCount = 0;
                 inStatementIndentStack->back() = 0;
@@ -2519,7 +2519,7 @@
                     headerStack->pop_back();
 
                     // do not indent namespace bracket unless namespaces are indented
-                    if (!namespaceIndent && headerStack->size() > 0
+                    if (!namespaceIndent && !headerStack->empty()
                             && (*headerStack).back() == &AS_NAMESPACE
                             && i == 0)        // must be the first bracket on the line
                         shouldIndentBrackettedLine = false;
@@ -2583,7 +2583,7 @@
                     // do not need second 'class' statement in a row
                     else if (!(newHeader == &AS_WHERE
                                || (newHeader == &AS_CLASS
-                                   && headerStack->size() > 0
+                                   && !headerStack->empty()
                                    && headerStack->back() == &AS_CLASS)))
download for full patch...
xazax-hun 2011-08-30 13:26

Prefix ++/-- operators should be preferred for non-primitive types. Pre-increment/decrement can be more efficient than post-increment/decrement. Post-increment/decrement usually involves keeping a copy of the previous value around and adds a little extra code. This optimization is applied on iterators.

Using foo.empty() instead of foo.size() can be faster. foo.size() can take linear time but foo.empty() is guaranteed to take constant time.

Possible null pointer dereference fixes.

Removed some redundant to check if something is null.

Exceptions should be caught by (const) reference.

Found and removed a duplicate if expression.