short circuit is_diacritic for 5-15% text drawing speed-up

characters less than the first diacritic in the symbol table (0x300)
return false after checking the MRU table

we gain some performance by eliding the function call all together if less than first diacritic

Change-Id: I02c14e350eb168eca808523affad443cd43888b4
This commit is contained in:
William Wilgus 2025-01-31 13:36:50 -05:00
parent c5103bab95
commit f501dd00eb
4 changed files with 16 additions and 6 deletions

View file

@ -50,7 +50,7 @@ struct diac_range
static const struct diac_range diac_ranges[] = static const struct diac_range diac_ranges[] =
{ {
DIAC_RANGE_ENTRY(0x0000, 0x0000, 0), DIAC_RANGE_ENTRY(0x0000, 0x0000, 0),
DIAC_RANGE_ENTRY(0x0300, 0x0370, 0), DIAC_RANGE_ENTRY(FIRST_DIACRITIC, 0x0370, 0),
DIAC_RANGE_ENTRY(0x0483, 0x048a, 0), DIAC_RANGE_ENTRY(0x0483, 0x048a, 0),
DIAC_RANGE_ENTRY(0x0591, 0x05be, 1), DIAC_RANGE_ENTRY(0x0591, 0x05be, 1),
DIAC_RANGE_ENTRY(0x05bf, 0x05c0, 1), DIAC_RANGE_ENTRY(0x05bf, 0x05c0, 1),

View file

@ -434,7 +434,7 @@ static void LCDFN(putsxyofs)(int x, int y, int ofs, const unsigned char *str)
if (x >= vp->width) if (x >= vp->width)
break; break;
is_diac = is_diacritic(*ucs, &is_rtl); is_diac = IS_DIACRITIC_RTL(*ucs, &is_rtl);
/* Get proportional width and glyph bits */ /* Get proportional width and glyph bits */
width = font_get_width(pf, *ucs); width = font_get_width(pf, *ucs);
@ -450,7 +450,7 @@ static void LCDFN(putsxyofs)(int x, int y, int ofs, const unsigned char *str)
const unsigned short *u; const unsigned short *u;
/* Jump to next non-diacritic char, and calc its width */ /* Jump to next non-diacritic char, and calc its width */
for (u = &ucs[1]; *u && is_diacritic(*u, NULL); u++); for (u = &ucs[1]; *u && IS_DIACRITIC(*u); u++);
rtl_next_non_diac_width = *u ? font_get_width(pf, *u) : 0; rtl_next_non_diac_width = *u ? font_get_width(pf, *u) : 0;
} }
@ -510,7 +510,7 @@ static void LCDFN(putsxyofs)(int x, int y, int ofs, const unsigned char *str)
if (next_ch) if (next_ch)
{ {
bool next_is_rtl; bool next_is_rtl;
bool next_is_diacritic = is_diacritic(next_ch, &next_is_rtl); bool next_is_diacritic = IS_DIACRITIC_RTL(next_ch, &next_is_rtl);
/* Increment if: /* Increment if:
* LTR: Next char is not diacritic, * LTR: Next char is not diacritic,

View file

@ -1084,7 +1084,7 @@ int font_getstringnsize(const unsigned char *str, size_t maxbytes, int *w, int *
for (str = utf8decode(str, &ch); ch != 0 && b < maxbytes; str = utf8decode(str, &ch), b--) for (str = utf8decode(str, &ch); ch != 0 && b < maxbytes; str = utf8decode(str, &ch), b--)
{ {
if (is_diacritic(ch, NULL)) if (IS_DIACRITIC(ch))
continue; continue;
/* get proportional width and glyph bits*/ /* get proportional width and glyph bits*/

View file

@ -22,9 +22,19 @@
#define _DIACRITIC_H_ #define _DIACRITIC_H_
#include "system.h" #include "system.h"
#define FIRST_DIACRITIC (0x0300)
/* Tests whether a given charactor code is a diacritic mark. /* Tests whether a given charactor code is a diacritic mark.
* Sets is_rtl (if it's not NULL) to whether the character * Sets is_rtl (if it's not NULL) to whether the character
* belongs to an RTL language. * belongs to an RTL language.
*/ */
bool is_diacritic(const unsigned short char_code, bool *is_rtl); bool is_diacritic(const unsigned short char_code, bool *is_rtl);
/* Note IS_DIACRITIC macros may elide the function call
* therefore there is a separate _RTL version that requires a bool pointer
* as it sets the variable to false when the is_diacritic func is skipped
*/
#define IS_DIACRITIC(c) (c >= FIRST_DIACRITIC && is_diacritic(c, NULL))
/* sets the rtl variable to false when function call is skipped */
#define IS_DIACRITIC_RTL(c, rtl) ((c >= FIRST_DIACRITIC || ( (*rtl = false) )) && is_diacritic(c, rtl))
#endif #endif