From: Matthew Fernandez Date: Sat, 15 Aug 2020 20:30:48 +0000 (-0700) Subject: replace agxbuse/alloc pattern with agxbdisown X-Git-Tag: 2.46.0~20^2^2~117^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18eed4fb5b151b0be7d8934203b58ffccc7d0b94;p=graphviz replace agxbuse/alloc pattern with agxbdisown Instead of retrieving the contents of a (possibly dynamically allocated) buffer and then allocating new space for a copy, we can simply take ownership of the original buffer. This saves an extra unnecessary allocation. --- diff --git a/cmd/smyrna/gui/menucallbacks.c b/cmd/smyrna/gui/menucallbacks.c index 39aa13fc1..48685c7f6 100644 --- a/cmd/smyrna/gui/menucallbacks.c +++ b/cmd/smyrna/gui/menucallbacks.c @@ -431,7 +431,7 @@ static char **splitArgs(const char *args, int *argcp) asize += 10; argv = ALLOC(asize, argv, char *); } - argv[argc++] = strdup(agxbuse(&xbuf)); + argv[argc++] = agxbdisown(&xbuf); } agxbfree(&xbuf); diff --git a/lib/common/htmlparse.y b/lib/common/htmlparse.y index 4d1656533..ef11e382d 100644 --- a/lib/common/htmlparse.y +++ b/lib/common/htmlparse.y @@ -179,7 +179,7 @@ appendFItemList (agxbuf *ag) { fitem *fi = NEW(fitem); - fi->ti.str = strdup(agxbuse(ag)); + fi->ti.str = agxbdisown(ag); fi->ti.font = HTMLstate.fontstack->cfont; dtinsert(HTMLstate.fitemList, fi); } diff --git a/lib/common/utils.c b/lib/common/utils.c index 17ba7834c..c71f72f6d 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -1552,7 +1552,7 @@ char* htmlEntityUTF8 (char* s, graph_t* g) } agxbputc(&xb, c); } - ns = strdup (agxbuse(&xb)); + ns = agxbdisown(&xb); agxbfree(&xb); return ns; } @@ -1591,7 +1591,7 @@ char* latin1ToUTF8 (char* s) agxbputc(&xb, (v & 0x3F) | 0x80); } } - ns = strdup (agxbuse(&xb)); + ns = agxbdisown(&xb); agxbfree(&xb); return ns; } @@ -1622,7 +1622,7 @@ utf8ToLatin1 (char* s) agxbputc(&xb, outc); } } - ns = strdup (agxbuse(&xb)); + ns = agxbdisown(&xb); agxbfree(&xb); return ns; } diff --git a/plugin/pango/gvgetfontlist_pango.c b/plugin/pango/gvgetfontlist_pango.c index e9df11911..c8c90e20d 100644 --- a/plugin/pango/gvgetfontlist_pango.c +++ b/plugin/pango/gvgetfontlist_pango.c @@ -481,7 +481,7 @@ static char *gv_get_font(availfont_t* gv_af_p, } } } - return strdup(agxbuse(xb2)); + return agxbdisown(xb2); } } return NULL;