From: Matthew Fernandez Date: Fri, 14 May 2021 00:07:53 +0000 (-0700) Subject: optimize 0 case in xdot_fmt_num X-Git-Tag: 2.47.2~2^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc37b655bd4a976238f83439d9b1311a61a987a5;p=graphviz optimize 0 case in xdot_fmt_num 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. --- diff --git a/plugin/core/gvrender_core_dot.c b/plugin/core/gvrender_core_dot.c index 4ddb68f1d..602c87cbe 100644 --- a/plugin/core/gvrender_core_dot.c +++ b/plugin/core/gvrender_core_dot.c @@ -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);