Improving log macro performances
The way logging macros are defined, they could consume a lot of time if passed slow functions. IOW,
otbMsgDevMacro(somethingslowandcalledforeachpixel());
would yield to inefficient code.
The usual way to fix this would be
#define otbLogMacro(level,msg) \
if (otb::Logger::Instance()->ShouldWeLog(level)) \ // <-- the new line
{ \
std::ostringstream itkmsg; \
itkmsg msg << "\n"; \
otb::Logger::Instance()->level(itkmsg.str().c_str()); \
}
BTW, the std::string
shall not be converted into a char const*
to be converted back into an std::string
-> get rid of .c_str()
.