Encourage compilers to optimize out debug() and debugData().

It's sort of like a throwback, but I found that debug(const String &s) {} doesn't prevent a String from being constructed and the error messages from being embedded.
This commit is contained in:
Tsuda Kageyu 2016-10-28 11:19:51 +09:00
parent d53ca6f736
commit 711b35cc6e
2 changed files with 15 additions and 11 deletions

View File

@ -27,6 +27,8 @@
#include <config.h>
#endif
#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE)
#include "tdebug.h"
#include "tstring.h"
#include "tdebuglistener.h"
@ -43,17 +45,11 @@ namespace TagLib
void debug(const String &s)
{
#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE)
debugListener->printMessage("TagLib: " + s + "\n");
#endif
}
void debugData(const ByteVector &v)
{
#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE)
for(size_t i = 0; i < v.size(); ++i)
{
std::string bits = std::bitset<8>(v[i]).to_string();
@ -63,7 +59,7 @@ namespace TagLib
debugListener->printMessage(msg);
}
#endif
}
}
#endif

View File

@ -32,10 +32,11 @@ namespace TagLib {
class ByteVector;
#ifndef DO_NOT_DOCUMENT
#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE)
/*!
* A simple function that outputs the debug messages to the listener.
* The default listener redirects the messages to \a stderr when NDEBUG is
* A simple function that outputs the debug messages to the listener.
* The default listener redirects the messages to \a stderr when NDEBUG is
* not defined.
*
* \warning Do not use this outside of TagLib, it could lead to undefined
@ -45,7 +46,7 @@ namespace TagLib {
* \internal
*/
void debug(const String &s);
/*!
* For debugging binary data.
*
@ -56,6 +57,13 @@ namespace TagLib {
* \internal
*/
void debugData(const ByteVector &v);
#else
#define debug(x) ((void)0)
#define debugData(x) ((void)0)
#endif
}
#endif