The analyzer detected a function that looks for a character in a string and can be optimized.
Consider the following example of inefficient code:
bool isSharpPresent(const std::string& str)
{
return str.find("#") != std::string::npos;
}
In this code, it is better to use an overridden version of the find function that receives a character instead of a string.
Optimized code:
bool isSharpPresent(const std::string& str)
{
return str.find('#') != std::string::npos;
}
The following example also uses inefficient code that can be optimized:
const char* GetSharpSubStr(const char* str)
{
return strstr(str, "#");
}
In this code, it is better to use the strchr function to search for a character instead of a string:
const char* GetSharpSubStr(const char* str)
{
return strchr(str, '#');
}
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders:
Take
a chance!