summaryrefslogtreecommitdiff
path: root/pango/pango-emoji.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2023-01-17 21:47:50 -0500
committerMatthias Clasen <mclasen@redhat.com>2023-01-17 21:53:52 -0500
commit5d20caf511b8b7f83b97637be5bc9e756bf3781a (patch)
treed4f020f4caa05fd5579a9de013852d1e09997902 /pango/pango-emoji.c
parent7b4a7d6dc00365289bece029e6698d01441bfb1f (diff)
downloadpango-5d20caf511b8b7f83b97637be5bc9e756bf3781a.tar.gz
Avoid some small allocations
Diffstat (limited to 'pango/pango-emoji.c')
-rw-r--r--pango/pango-emoji.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/pango/pango-emoji.c b/pango/pango-emoji.c
index e1f16dba..83ebfe6e 100644
--- a/pango/pango-emoji.c
+++ b/pango/pango-emoji.c
@@ -213,14 +213,19 @@ typedef unsigned char *emoji_text_iter_t;
PangoEmojiIter *
_pango_emoji_iter_init (PangoEmojiIter *iter,
- const char *text,
- int length)
+ const char *text,
+ int length,
+ unsigned int n_chars)
{
- unsigned int n_chars = g_utf8_strlen (text, length);
- unsigned char *types = g_malloc (n_chars);
+ unsigned char *types;
unsigned int i;
const char *p;
+ if (n_chars < 64)
+ types = iter->types_;
+ else
+ types = g_malloc (n_chars);
+
p = text;
for (i = 0; i < n_chars; i++)
{
@@ -247,7 +252,8 @@ _pango_emoji_iter_init (PangoEmojiIter *iter,
void
_pango_emoji_iter_fini (PangoEmojiIter *iter)
{
- g_free (iter->types);
+ if (iter->types != iter->types_)
+ g_free (iter->types);
}
gboolean