]> git.wh0rd.org Git - fontconfig.git/commitdiff
[fcstr.c] Embed a static 64-byte buffer in FcStrBuf
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 11 Mar 2009 17:56:09 +0000 (13:56 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 12 Mar 2009 17:14:37 +0000 (13:14 -0400)
Reduces number of mallocs called from FcStrBufChar in my small test
from 900 down to 6.

src/fcint.h
src/fcstr.c

index b667e5476b4c9dc62c53eef570758c49ab974d9a..be520e78624cf522e34731a321d69a52fad65f9b 100644 (file)
@@ -313,6 +313,7 @@ typedef struct _FcStrBuf {
     FcBool  failed;
     int            len;
     int            size;
+    FcChar8 buf_static[16 * sizeof (void *)];
 } FcStrBuf;
 
 struct _FcCache {
index 3b84ac0d179dad85ad8d89aeaf0eaf4dce68d351..4fbb1a216ea88fd551027b26d25cdea10df0cc17 100644 (file)
@@ -710,11 +710,18 @@ FcUtf16Len (const FcChar8   *string,
 void
 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size)
 {
-    buf->buf = init;
+    if (init)
+    {
+       buf->buf = init;
+       buf->size = size;
+    } else
+    {
+       buf->buf = buf->static_buf;
+       buf->size = sizeof (buf->static_buf);
+    }
     buf->allocated = FcFalse;
     buf->failed = FcFalse;
     buf->len = 0;
-    buf->size = size;
 }
 
 void