C
Christian Christmann
Hi,
I've profiled one of my C++ projects and figured out that the
program spends a lot of time with STL map's function "find".
One of my classes possesses an STL map of the structure
map< string, string > myMap;
The function that consumes a substantial fraction of the
program execution, searches in the map:
string findString( const char *lab )
{
string tmp( lab );
map< string, string >::const_iterator it = myMap.find( tmp.c_str() );
if ( it != myMap.end() ) {
string myString( it->second.c_str() );
return myString;
}
// Otherwise
string myString( lab );
return myString;
}
Do you see any possibility to optimize the "find" function on "myMap"?
And in general, do you have any suggestions how to improve the function
"findString"?
Regards,
Chris
I've profiled one of my C++ projects and figured out that the
program spends a lot of time with STL map's function "find".
One of my classes possesses an STL map of the structure
map< string, string > myMap;
The function that consumes a substantial fraction of the
program execution, searches in the map:
string findString( const char *lab )
{
string tmp( lab );
map< string, string >::const_iterator it = myMap.find( tmp.c_str() );
if ( it != myMap.end() ) {
string myString( it->second.c_str() );
return myString;
}
// Otherwise
string myString( lab );
return myString;
}
Do you see any possibility to optimize the "find" function on "myMap"?
And in general, do you have any suggestions how to improve the function
"findString"?
Regards,
Chris