News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

unused tree pointer variable in CC

Started by ollydbg, February 07, 2012, 07:55:07 AM

Previous topic - Next topic

ollydbg

When build CC, I find some un-used variables, like:

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.

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.

MortenMacFly

Quote from: ollydbg on February 07, 2012, 07:55:07 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]