]> granicus.if.org Git - taglib/commitdiff
Encourage compilers to optimize out debug() and debugData().
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 28 Oct 2016 02:19:51 +0000 (11:19 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 28 Oct 2016 02:19:51 +0000 (11:19 +0900)
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.

taglib/toolkit/tdebug.cpp
taglib/toolkit/tdebug.h

index 557baed6ec6a1841c9add6e757097a26e94bdcdb..d630791c177ff65e43cc148e7842d6d4110a8a56 100644 (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
index bd94d159fca93f92b68310c7ba1f1519b3b7e561..80d00d39e571e5305d91c9cec3b84dcc8c376691 100644 (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