Author Topic: unused tree pointer variable in CC  (Read 8237 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
unused tree pointer variable in CC
« on: February 07, 2012, 07:55:07 am »
When build CC, I find some un-used variables, like:
Code
size_t NativeParser::ResolveActualType(wxString searchText, const TokenIdxSet& searchScope, TokenIdxSet& result)
{
    // break up the search text for next analysis.
    std::queue<ParserComponent> typeComponents;
    BreakUpComponents(searchText, typeComponents);
    if (!typeComponents.empty())
    {
        TokenIdxSet initialScope;
        if (!searchScope.empty())
            initialScope = searchScope;
        else
            initialScope.insert(-1);

        TokensTree* tree = m_Parser->GetTokensTree(); // accessed by GenerateResultSet

        CC_LOCKER_TRACK_TT_MTX_LOCK(s_TokensTreeMutex)

        while (!typeComponents.empty())
        {
            TokenIdxSet initialResult;
            ParserComponent component = typeComponents.front();
            typeComponents.pop();
            wxString actualTypeStr = component.component;

            // All functions that call the recursive GenerateResultSet should already entered a critical section.
            GenerateResultSet(actualTypeStr, initialScope, initialResult, true, false, 0xFFFF);

            if (!initialResult.empty())
            {
                initialScope.clear();
                for (TokenIdxSet::iterator it = initialResult.begin(); it != initialResult.end(); ++it)
                    // TODO (blueshake#1#): eclimate the variable/function
                    initialScope.insert(*it);
            }
            else
            {
                initialScope.clear();
                break;
            }
        }

        CC_LOCKER_TRACK_TT_MTX_UNLOCK(s_TokensTreeMutex)

        if (!initialScope.empty())
            result = initialScope;
    }

    return result.size();
}

What does this means? comments is still confusing.
Code
TokensTree* tree = m_Parser->GetTokensTree(); // accessed by GenerateResultSet
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: unused tree pointer variable in CC
« Reply #1 on: February 07, 2012, 09:10:25 am »
TokensTree* tree = m_Parser->GetTokensTree(); // accessed by GenerateResultSet
You can comment these lines. They were for me to understand, what tree has to be locked when calling one of the recursive functions that require a lock from "outside" (i.e. the caller). Don't remove, just comment please.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ