Subject: bug#39133: 28.0.50; Emacs slowdown on special char

From: Robert Pluim <[email-masked]>
Date: Wed, 15 Jan 2020 09:25:43 +0100

>>>>> On Wed, 15 Jan 2020 13:26:11 +0900, YAMAMOTO Mitsuharu <[email-masked]> said:

    YAMAMOTO> 0xFFFFFFFF comes from FONT_INVALID_CODE. font->driver->text_extents
    YAMAMOTO> shouldn't be called if font->font->driver->encode_char returns it.

    YAMAMOTO> diff --git a/src/font.c b/src/font.c
    YAMAMOTO> index 2b90903c90..03e6176220 100644
    YAMAMOTO> --- a/src/font.c
    YAMAMOTO> +++ b/src/font.c
    YAMAMOTO> @@ -4420,15 +4420,19 @@ font_fill_lglyph_metrics (Lisp_Object glyph, Lisp_Object font_object)
    YAMAMOTO>  {
    YAMAMOTO>    struct font *font = XFONT_OBJECT (font_object);
    YAMAMOTO>    unsigned code = font->driver->encode_char (font, LGLYPH_CHAR (glyph));
    YAMAMOTO> -  struct font_metrics metrics;
    YAMAMOTO> -
    YAMAMOTO> -  LGLYPH_SET_CODE (glyph, code);
    YAMAMOTO> -  font->driver->text_extents (font, &code, 1, &metrics);
    YAMAMOTO> -  LGLYPH_SET_LBEARING (glyph, metrics.lbearing);
    YAMAMOTO> -  LGLYPH_SET_RBEARING (glyph, metrics.rbearing);
    YAMAMOTO> -  LGLYPH_SET_WIDTH (glyph, metrics.width);
    YAMAMOTO> -  LGLYPH_SET_ASCENT (glyph, metrics.ascent);
    YAMAMOTO> -  LGLYPH_SET_DESCENT (glyph, metrics.descent);
    YAMAMOTO> +
    YAMAMOTO> +  if (code != FONT_INVALID_CODE)
    YAMAMOTO> +    {
    YAMAMOTO> +      struct font_metrics metrics;
    YAMAMOTO> +
    YAMAMOTO> +      LGLYPH_SET_CODE (glyph, code);
    YAMAMOTO> +      font->driver->text_extents (font, &code, 1, &metrics);
    YAMAMOTO> +      LGLYPH_SET_LBEARING (glyph, metrics.lbearing);
    YAMAMOTO> +      LGLYPH_SET_RBEARING (glyph, metrics.rbearing);
    YAMAMOTO> +      LGLYPH_SET_WIDTH (glyph, metrics.width);
    YAMAMOTO> +      LGLYPH_SET_ASCENT (glyph, metrics.ascent);
    YAMAMOTO> +      LGLYPH_SET_DESCENT (glyph, metrics.descent);
    YAMAMOTO> +    }
    YAMAMOTO>  }

    YAMAMOTO> But I'm not sure if it is ok to leave the code and metrics-related
    YAMAMOTO> fields nil when encode_char returns FONT_INVALID_CODE.  Handa-san?

I donʼt know either, but your patch fixes the slowdown and Iʼve seen
no negative effects yet.

Robert