about summary refs log tree commit diff
path: root/src/libnix/util.hh
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-11-09T10·35+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-11-09T10·35+0000
commit15801c88fad38253b19ac2ea77e7597deab5fd6b (patch)
tree2dab8ab76792328b6c5376509d6b2e659ad19cf8 /src/libnix/util.hh
parentd2e3a132fe6796b2ac038ccb20e7aa32afc1a85f (diff)
* Turned the msg() and debug() functions into macros, since they
  turned out to be a huge performance bottleneck (the text to printed
  would always be evaluated, even when it was above the verbosity
  level).  This reduces fix-ng execution time by over 50%.

  gprof(1) is very useful. :-)

Diffstat (limited to 'src/libnix/util.hh')
-rw-r--r--src/libnix/util.hh21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/libnix/util.hh b/src/libnix/util.hh
index 02a9b7fcb885..e6b600eff8ce 100644
--- a/src/libnix/util.hh
+++ b/src/libnix/util.hh
@@ -101,12 +101,27 @@ class Nest
 private:
     bool nest;
 public:
-    Nest(Verbosity level, const format & f);
+    Nest();
     ~Nest();
+    void open(Verbosity level, const format & f);
 };
 
-void msg(Verbosity level, const format & f);
-void debug(const format & f); /* short-hand for msg(lvlDebug, ...) */
+void printMsg_(Verbosity level, const format & f);
+
+#define startNest(varName, level, f) \
+    Nest varName; \
+    if (level <= verbosity) { \
+      varName.open(level, (f)); \
+    }
+
+#define printMsg(level, f) \
+    do { \
+        if (level <= verbosity) { \
+            printMsg_(level, (f)); \
+        } \
+    } while (0)
+
+#define debug(f) printMsg(lvlDebug, f)
 
 
 /* Wrappers arount read()/write() that read/write exactly the