]> granicus.if.org Git - graphviz/commitdiff
replace agxbuse/alloc pattern with agxbdisown
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 15 Aug 2020 20:30:48 +0000 (13:30 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 20 Aug 2020 14:40:31 +0000 (07:40 -0700)
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
lib/common/htmlparse.y
lib/common/utils.c
plugin/pango/gvgetfontlist_pango.c

index 39aa13fc1be97d330365a2cb75fd5e7e636e702e..48685c7f644690ca506b21dbf1bd6c9cf425106e 100644 (file)
@@ -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);
index 4d16565337a28983220c1fe26b04540b3833a158..ef11e382d9f9d7b4fb64911e017f2f706a932c2e 100644 (file)
@@ -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);
 }      
index 17ba7834c8bb78a5c67b1a097974e4509bf3f111..c71f72f6d9219debcbdf73ab696a07f7f6541e7b 100644 (file)
@@ -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;
 }
index e9df1191129bcb24ff998f5482940ecb7c95565a..c8c90e20d6d3236d69c1654e663c6fdd9d0d8c83 100644 (file)
@@ -481,7 +481,7 @@ static char *gv_get_font(availfont_t* gv_af_p,
                    }
                }
            }
-           return strdup(agxbuse(xb2));
+           return agxbdisown(xb2);
        }
     }
     return NULL;