Changed implementation of logging macros.

We have observed some strange performance-related behavior as described here: https://stackoverflow.com/questions/29652787/adding-stringstream-cout-hurts-performance-even-when-the-code-is-never-called

This set of changes addresses this problem. The old macros would simply expand the logging code in place, whereas we now have logging functions and the macros call these. Overall I believe it is tidier.
This commit is contained in:
David Williams
2015-05-07 22:58:00 +02:00
parent 4dadbbffd1
commit f16a247934
6 changed files with 156 additions and 288 deletions

View File

@ -116,40 +116,26 @@ freely, subject to the following restrictions:
* ...
*/
#ifdef POLYVOX_THROW_ENABLED
namespace PolyVox
{
template< typename ExceptionType, typename ... Args >
void polyvox_throw(Args const& ... messageArgs)
{
std::string message = Impl::argListToString(messageArgs...);
#ifdef POLYVOX_LOG_ERROR_ENABLED
PolyVox::Impl::getLoggerInstance()->logErrorMessage(message);
#endif
throw ExceptionType(message);
}
#define POLYVOX_THROW_IF(condition, type, message) \
/* We use the do...while(0) construct in our macros (for reasons see here: http://stackoverflow.com/a/154138) \
but Visual Studio gives unhelpful 'conditional expression is constant' warnings. The recommended solution \
(http://stackoverflow.com/a/1946485) is to disable these warnings. */ \
POLYVOX_MSC_WARNING_PUSH \
POLYVOX_DISABLE_MSC_WARNING(4127) \
do \
{ \
if ((condition)) \
{ \
std::stringstream ss; \
ss << message; \
PolyVox::Impl::getLoggerInstance()->logErrorMessage(ss.str()); \
throw type(ss.str()); \
} \
} while(0) \
POLYVOX_MSC_WARNING_POP
#define POLYVOX_THROW(type, message) \
/* We use the do...while(0) construct in our macros (for reasons see here: http://stackoverflow.com/a/154138) \
but Visual Studio gives unhelpful 'conditional expression is constant' warnings. The recommended solution \
(http://stackoverflow.com/a/1946485) is to disable these warnings. */ \
POLYVOX_MSC_WARNING_PUSH \
POLYVOX_DISABLE_MSC_WARNING(4127) \
do \
{ \
std::stringstream ss; \
ss << message; \
PolyVox::Impl::getLoggerInstance()->logErrorMessage(ss.str()); \
throw type(ss.str()); \
} while(0) \
POLYVOX_MSC_WARNING_POP
template< typename ExceptionType, typename ... Args >
void polyvox_throw_if(bool condition, Args const& ... messageArgs)
{
if(condition) { polyvox_throw<ExceptionType>(messageArgs...); }
}
}
#define POLYVOX_THROW(type, ...) PolyVox::polyvox_throw<type>(__VA_ARGS__)
#define POLYVOX_THROW_IF(condition, type, ...) PolyVox::polyvox_throw_if<type>(condition, __VA_ARGS__)
#else
namespace PolyVox
{