I have been randomly browsing through the source code trying to
comprehend what I see.

I see one area for possible improvements in Window.cpp. There are a lot
of loops that look like this:

-------------------------------------------------------------------------
Error Window::ControlStringValue(const string &oTarget, bool bSet, string &oValue)
{
    ControlMapIterator  i;
    int                 j;

    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
       
    for(i = m_oControlMap.find(oTarget), j = 0; 
        j != (int)m_oControlMap.count(oTarget); j++, i++) 
    {
         (*i).second->StringValue(bSet, oValue);
    }        

    return (j == 0) ? kError_InvalidParam : kError_NoErr;
}
-------------------------------------------------------------------------

If I'm right (there is no documentation of course for any of these
methods), the above loop sets a value on all elements in the
multimap which have a key of oTarget. If no such elements were
found, then the method returns an error.

It is inefficient to call the count method each time through the
loop in order to determine the number of elements with that key.
To an STL programmer, it also looks strange and is hard to understand.

I think you can make this easier to understand and more efficient
by using the equal_range method to accomplish the same goal (forgive
my formatting):

-------------------------------------------------------------------------
Error Window::ControlStringValue(const string &oTarget, bool bSet, string &oValue)
{
    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
    
    pair<ControlMapIterator, ControlMapIterator> keyRange
        = m_oControlMap.equal_range(oTarget);

    for (ControlMapIterator i = keyRange.first; i != keyRange.second; i++)
    {
        i->second->StringValue(bSet, oValue);
    }

    return (keyRange.first == keyRange.second)
                ? kError_InvalidParam : kError_NoErr;
}
-------------------------------------------------------------------------

I have tested the changes on my system and they work fine. I can provide
a CVS diff if anyone is interested (I don't have write access to the
CVS server).

Any comments?

        c

----------------------------------------------------
| Chad Loder - Somerville, MA, USA                 |
| EMail:     [EMAIL PROTECTED]                        |
| Home Page: http://www.ccs.neu.edu/home/cloder    |
----------------------------------------------------




_______________________________________________
[EMAIL PROTECTED]
http://www.freeamp.org/mailman/listinfo/freeamp-dev

Reply via email to