]> granicus.if.org Git - graphviz/commitdiff
optimize 0 case in xdot_fmt_num
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 14 May 2021 00:07:53 +0000 (17:07 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 20 May 2021 02:57:08 +0000 (19:57 -0700)
Commit 894e94c66340187ff6f8ea97c9336ea048a3d6ad applied a performance
optimization to gvprintdouble that was contributing to a performance issue in a
user’s graph. The code touched in this commit has the same pattern as that in
gvprintdouble, and the same corresponding (latent) performance issue. While it
is not known to cause any problems currently, we may as well proactively apply
the same optimization here.

This preserves the same functionality, but simply takes an early exit from the
function when we already know precisely how to print the resulting string.

plugin/core/gvrender_core_dot.c

index 4ddb68f1d032e82f9058209f88dab26ae96fc1e5..602c87cbe91dae58d064470f2adfac3a93edabbb 100644 (file)
@@ -128,7 +128,8 @@ static void xdot_fmt_num (char* buf, double v)
     // Prevents values like -0
     if (v > -0.00000001 && v < 0.00000001)
     {
-        v = 0;
+        strcpy(buf, "0 ");
+        return;
     }
     sprintf(buf, "%.02f", v);
     xdot_trim_zeros (buf, 1);