Speed up tracing by factor of 4-6, by writing less stupid code.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 20 Jul 2009 12:55:46 +0000 (22:25 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 20 Jul 2009 12:55:46 +0000 (22:25 +0930)
ccan/tdb/tdb.c

index 3acf05b96e15fdebc4ef893139a477907d293a30..c44987a14e01f343c008e403eb789bd3973a33dd 100644 (file)
@@ -874,7 +874,7 @@ static void tdb_trace_end_ret(struct tdb_context *tdb, int ret)
 
 static void tdb_trace_record(struct tdb_context *tdb, TDB_DATA rec)
 {
-       char msg[20];
+       char msg[20 + rec.dsize*2], *p;
        unsigned int i;
 
        /* We differentiate zero-length records from non-existent ones. */
@@ -882,12 +882,13 @@ static void tdb_trace_record(struct tdb_context *tdb, TDB_DATA rec)
                tdb_trace_write(tdb, " NULL");
                return;
        }
-       sprintf(msg, " %zu:", rec.dsize);
+
+       p = msg;
+       p += sprintf(p, " %zu:", rec.dsize);
+       for (i = 0; i < rec.dsize; i++)
+               p += sprintf(p, "%02x", rec.dptr[i]);
+
        tdb_trace_write(tdb, msg);
-       for (i = 0; i < rec.dsize; i++) {
-               sprintf(msg, "%02x", rec.dptr[i]);
-               tdb_trace_write(tdb, msg);
-       }
 }
 
 void tdb_trace(struct tdb_context *tdb, const char *op)