]> granicus.if.org Git - graphviz/commitdiff
take an early exit when gvprintdouble-ing a "0"
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 6 Oct 2020 01:14:31 +0000 (18:14 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 12 Oct 2020 02:58:06 +0000 (19:58 -0700)
In large graphs, the value being printed is frequently zero and the snprintf in
this function shows up as a minor hotspot. Profiling with
tests/regression_tests/large/long_chain this drops the total snprintf calls
within gvprintdouble from 924019 to 858017. This lowers the contributing runtime
of gvprintdouble to overall execution from 28.89% to 28.12%.

lib/gvc/gvdevice.c

index 03a348d0261e88bf8025737c08fd26371dc0cc69..145f99a7f8c5e3d0bd4fe6c51d210592781c24e6 100644 (file)
@@ -562,7 +562,8 @@ void gvprintdouble(GVJ_t * job, double num)
     // Prevents values like -0
     if (num > -0.00000001 && num < 0.00000001)
     {
-        num = 0;
+        gvwrite(job, "0", 1);
+        return;
     }
 
     char buf[50];