From 7d35c11b3304659d8be43913c9b125f2b5b38516 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Mar 2009 13:56:09 -0400 Subject: [PATCH] [fcstr.c] Embed a static 64-byte buffer in FcStrBuf Reduces number of mallocs called from FcStrBufChar in my small test from 900 down to 6. --- src/fcint.h | 1 + src/fcstr.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/fcint.h b/src/fcint.h index b667e54..be520e7 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -313,6 +313,7 @@ typedef struct _FcStrBuf { FcBool failed; int len; int size; + FcChar8 buf_static[16 * sizeof (void *)]; } FcStrBuf; struct _FcCache { diff --git a/src/fcstr.c b/src/fcstr.c index 3b84ac0..4fbb1a2 100644 --- a/src/fcstr.c +++ b/src/fcstr.c @@ -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 -- 2.39.5