From 4ea0f232ef87a34ecd87911b52e85028fbe56fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Sat, 23 May 2020 21:29:00 -0300 Subject: [PATCH] Use small buffer optimization in gfx_animation_ticker_smooth() Like the previous commit, this one lowers the number of temporary allocations while the menu is up. --- gfx/gfx_animation.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gfx/gfx_animation.c b/gfx/gfx_animation.c index 6eaac7e5f4..c00b2778f9 100644 --- a/gfx/gfx_animation.c +++ b/gfx/gfx_animation.c @@ -1706,9 +1706,15 @@ bool gfx_animation_ticker_smooth(gfx_animation_ctx_ticker_smooth_t *ticker) if (src_str_len < 1) goto end; - src_char_widths = (unsigned*)calloc(src_str_len, sizeof(unsigned)); - if (!src_char_widths) - goto end; + unsigned small_src_char_widths[64] = {0}; + src_char_widths = small_src_char_widths; + + if (src_str_len > ARRAY_SIZE(small_src_char_widths)) + { + src_char_widths = (unsigned*)calloc(src_str_len, sizeof(unsigned)); + if (!src_char_widths) + goto end; + } str_ptr = ticker->src_str; for (i = 0; i < src_str_len; i++) @@ -1881,7 +1887,7 @@ bool gfx_animation_ticker_smooth(gfx_animation_ctx_ticker_smooth_t *ticker) end: - if (src_char_widths) + if (src_char_widths != small_src_char_widths && src_char_widths) { free(src_char_widths); src_char_widths = NULL;