]> git.eshelyaron.com Git - emacs.git/commitdiff
Remove redundant call to expensive function XOpenDisplay
authorPo Lu <luangruo@yahoo.com>
Sat, 15 Oct 2022 08:25:22 +0000 (16:25 +0800)
committerPo Lu <luangruo@yahoo.com>
Sat, 15 Oct 2022 08:25:22 +0000 (16:25 +0800)
* 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.

src/xterm.c

index 0fca9788ce54cb49b2d5125deaa8156338c913b1..d35af7a8de2a41e183b5c4bc41100c7f2cb44486 100644 (file)
@@ -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;
     }