From: Po Lu Date: Sat, 15 Oct 2022 08:25:22 +0000 (+0800) Subject: Remove redundant call to expensive function XOpenDisplay X-Git-Tag: emacs-29.0.90~1616^2~614 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a06c54209499c3885c13a8d3eba7798ab3f0d688;p=emacs.git Remove redundant call to expensive function XOpenDisplay * src/xterm.c (x_term_init): Speed up opening Emacs over a slow network connection by an order of magnitude on no toolkit builds by avoiding a redundant call to XOpenDisplay. --- diff --git a/src/xterm.c b/src/xterm.c index 0fca9788ce5..d35af7a8de2 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -28527,9 +28527,10 @@ xi_check_toolkit (Display *display) #endif -/* Open a connection to X display DISPLAY_NAME, and return - the structure that describes the open display. - If we cannot contact the display, return null. */ +/* Open a connection to X display DISPLAY_NAME, and return the + structure that describes the open display. If obtaining the XCB + connection or toolkit-specific display fails, return NULL. Signal + an error if opening the display itself failed. */ struct x_display_info * x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) @@ -28556,9 +28557,13 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) ++x_initialized; } - if (! x_display_ok (SSDATA (display_name))) +#if defined USE_X_TOOLKIT || defined USE_GTK + + if (!x_display_ok (SSDATA (display_name))) error ("Display %s can't be opened", SSDATA (display_name)); +#endif + #ifdef USE_GTK { #define NUM_ARGV 10 @@ -28685,6 +28690,15 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) /* Detect failure. */ if (dpy == 0) { +#if !defined USE_X_TOOLKIT && !defined USE_GTK + /* Avoid opening a display three times (once in dispextern.c + upon startup, once in x_display_ok, and once above) to + determine whether or not the display is alive on no toolkit + builds, where no toolkit initialization happens at all. */ + + error ("Display %s can't be opened", SSDATA (display_name)); +#endif + unblock_input (); return 0; }