From 18eed4fb5b151b0be7d8934203b58ffccc7d0b94 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 15 Aug 2020 13:30:48 -0700 Subject: [PATCH] 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. --- cmd/smyrna/gui/menucallbacks.c | 2 +- lib/common/htmlparse.y | 2 +- lib/common/utils.c | 6 +++--- plugin/pango/gvgetfontlist_pango.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) 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; -- 2.40.0