emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: x-create-frame is sluggish


From: Károly Lőrentey
Subject: Re: x-create-frame is sluggish
Date: Mon, 11 Oct 2004 16:53:32 +0200
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

Jan Djärv <address@hidden> writes:
>> +       if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
>> +           && !strcmp (FRAME_XIC_BASE_FONTNAME (cf), base_fontname))
>> +         return FRAME_XIC_FONTSET (cf);
>> +     }
>
> You must check that the frames sharing the fontset is on the same 
> display.

>> +       if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
>> +           && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f))
>> +         return;
>
> And here also.
>
> You did not include diffs for xterm.c and xterm.h.

It looks like I messed up something while preparing my email.  How
embarassing!  Here is a revised patch that incorporates your points,
adds the missing patches and fixes a syntax error that somehow crept
into create_frame_xic.

2004-10-11  Károly Lőrentey  <address@hidden>

        * src/xterm.h (x_output): New member `xic_base_fontname'.
        (FRAME_XIC_BASE_FONTNAME): New macro.
        (xic_delete_xfontset): Declare.

        * src/xfns.c (xic_create_xfontset): Share fontsets between frames
        based on base_fontname.
        (create_frame_xic): Set the frame's xic_base_fontname.
        (xic_delete_xfontset): New function.
        (free_frame_xic): Use it.  Free xic_base_fontname.
        (xic_set_xfontset): Ditto.

        * src/xterm.c (xim_destroy_callback): Ditto.

*** orig/src/xfns.c
--- mod/src/xfns.c
***************
*** 1953,1959 ****
--- 1953,1971 ----
    char **missing_list;
    int missing_count;
    char *def_string;
+   Lisp_Object rest, frame;
  
+   /* See if there is another frame already using same fontset. */
+   FOR_EACH_FRAME (rest, frame)
+     {
+       struct frame *cf = XFRAME (frame);
+       if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
+           && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
+           && !strcmp (FRAME_XIC_BASE_FONTNAME (cf), base_fontname))
+         return FRAME_XIC_FONTSET (cf);
+     }
+ 
+   /* New fontset. */
    xfs = XCreateFontSet (FRAME_X_DISPLAY (f),
                        base_fontname, &missing_list,
                        &missing_count, &def_string);
***************
*** 1964,1969 ****
--- 1976,2005 ----
    return xfs;
  }
  
+ /* Free the X fontset of frame F if it is the last frame using it. */
+ 
+ void
+ xic_delete_xfontset (f)
+      struct frame *f;
+ {
+   Lisp_Object rest, frame;
+ 
+   if (!FRAME_XIC_FONTSET (f))
+     return;
+ 
+   /* See if there is another frame sharing the same fontset. */
+   FOR_EACH_FRAME (rest, frame)
+     {
+       struct frame *cf = XFRAME (frame);
+       if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
+           && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
+           && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f))
+         return;
+     }
+   /* The fontset is not used anymore.  It is safe to free it. */
+   XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
+ }
+ 
  
  /* Value is the best input style, given user preferences USER (already
     checked to be supported by Emacs), and styles supported by the
***************
*** 1996,2001 ****
--- 2032,2038 ----
    XIM xim;
    XIC xic = NULL;
    XFontSet xfs = NULL;
+   char *base_fontname = NULL;
  
    if (FRAME_XIC (f))
      return;
***************
*** 2007,2013 ****
        XPoint spot;
        XVaNestedList preedit_attr;
        XVaNestedList status_attr;
-       char *base_fontname;
        int fontset;
  
        s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1;
--- 2044,2049 ----
***************
*** 2101,2106 ****
--- 2137,2143 ----
    FRAME_XIC (f) = xic;
    FRAME_XIC_STYLE (f) = xic_style;
    FRAME_XIC_FONTSET (f) = xfs;
+   FRAME_XIC_BASE_FONTNAME (f) = xstrdup (base_fontname);
  }
  
  
***************
*** 2114,2124 ****
      return;
  
    XDestroyIC (FRAME_XIC (f));
!   if (FRAME_XIC_FONTSET (f))
!     XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
  
    FRAME_XIC (f) = NULL;
    FRAME_XIC_FONTSET (f) = NULL;
  }
  
  
--- 2151,2163 ----
      return;
  
    XDestroyIC (FRAME_XIC (f));
!   xic_delete_xfontset (f);
!   if (FRAME_XIC_BASE_FONTNAME (f))
!     xfree (FRAME_XIC_BASE_FONTNAME (f));
  
    FRAME_XIC (f) = NULL;
    FRAME_XIC_FONTSET (f) = NULL;
+   FRAME_XIC_BASE_FONTNAME (f) = NULL;
  }
  
  
***************
*** 2207,2214 ****
    XFree (attr);
  
    if (FRAME_XIC_FONTSET (f))
!     XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
    FRAME_XIC_FONTSET (f) = xfs;
  }
  
  #endif /* HAVE_X_I18N */
--- 2246,2258 ----
    XFree (attr);
  
    if (FRAME_XIC_FONTSET (f))
!     xic_delete_xfontset (f);
! 
!   if (FRAME_XIC_BASE_FONTNAME (f))
!     xfree (FRAME_XIC_BASE_FONTNAME (f));
! 
    FRAME_XIC_FONTSET (f) = xfs;
+   FRAME_XIC_BASE_FONTNAME (f) = xstrdup (base_fontname);
  }
  
  #endif /* HAVE_X_I18N */
*** orig/src/xterm.c
--- mod/src/xterm.c
***************
*** 8024,8031 ****
          FRAME_XIC (f) = NULL;
          if (FRAME_XIC_FONTSET (f))
            {
!             XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
              FRAME_XIC_FONTSET (f) = NULL;
            }
        }
      }
--- 8024,8033 ----
          FRAME_XIC (f) = NULL;
          if (FRAME_XIC_FONTSET (f))
            {
!               xic_delete_xfontset (f);
!               xfree (FRAME_XIC_BASE_FONTNAME (f));
              FRAME_XIC_FONTSET (f) = NULL;
+             FRAME_XIC_BASE_FONTNAME (f) = NULL;
            }
        }
      }
*** orig/src/xterm.h
--- mod/src/xterm.h
***************
*** 593,598 ****
--- 593,599 ----
    XIC xic;
    XIMStyle xic_style;
    XFontSet xic_xfs;
+   char *xic_base_fontname;
  #endif
  
    /* Relief GCs, colors etc.  */
***************
*** 727,732 ****
--- 728,734 ----
  #define FRAME_X_XIM_STYLES(f) (FRAME_X_DISPLAY_INFO (f)->xim_styles)
  #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
  #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
+ #define FRAME_XIC_BASE_FONTNAME(f) ((f)->output_data.x->xic_base_fontname)
  
  /* Value is the smallest width of any character in any font on frame F.  */
  
***************
*** 1036,1041 ****
--- 1038,1044 ----
  extern unsigned char * x_encode_text P_ ((Lisp_Object, Lisp_Object, int,
                                          int *, int *));
  extern void x_implicitly_set_name P_ ((struct frame *, Lisp_Object, 
Lisp_Object));
+ extern void xic_delete_xfontset P_ ((struct frame *));
  extern void create_frame_xic P_ ((struct frame *));
  extern void destroy_frame_xic P_ ((struct frame *));
  extern void xic_set_preeditarea P_ ((struct window *, int, int));
-- 
Károly

Attachment: pgpL6xaFs3n3E.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]