I have been working on some legacy C++ code and my objective is to optimize the code as much as possible. I was reading somewhere and found this code
// Bad Idea
class MyClass
{
public:
void do_something(int i);
void do_something(std::string str);
};
// Good Idea
class MyClass
{
public:
void do_something(const int i);
void do_something(const std::string &str);
};
This code says that use const
as much as possible. Could someone explain if this has a significant performance improvement or if it is related to something else?