]> granicus.if.org Git - graphviz/commitdiff
xdot sprintXDot: steal agxbuf’s buffer instead of double copying
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 9 Jul 2022 15:39:55 +0000 (08:39 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 16 Jul 2022 00:06:35 +0000 (17:06 -0700)
8064f6e902cc4c3062cffa2d1d307ee9cf1893bb replaced lib/xdot’s inline copy of a
subset of the agxbuf.h API with an include of the header containing the full
API. This gives us access to `agxbdisown`. This function effectively does the
work of `agxbuse;strdup;agxbfree` by taking the existing dynamically allocated
buffer within the `agxbuf` object, rather than making yet another copy of this
data only to discard the original.

lib/xdot/xdot.c

index 4d8f54df0a24d1ebee81bd096b8162c8b12f58b4..cdc06fb072e64ef28677dca7ad1a9d2c0c8b39d5 100644 (file)
@@ -784,8 +784,7 @@ char *sprintXDot(xdot * x)
     agxbuf xb;
     agxbinit(&xb, BUFSIZ, buf);
     _printXDot(x, agxbput_, &xb, printXDot_Op);
-    s = strdup(agxbuse(&xb));
-    agxbfree(&xb);
+    s = agxbdisown(&xb);
 
     return s;
 }