]> granicus.if.org Git - vim/commitdiff
patch 8.0.1800: X11: getting color is slow v8.0.1800
authorBram Moolenaar <Bram@vim.org>
Sun, 6 May 2018 17:19:36 +0000 (19:19 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 6 May 2018 17:19:36 +0000 (19:19 +0200)
Problem:    X11: getting color is slow.
Solution:   Avoid using sprintf() and XParseColor(), put the RGB values in
            XColor directly.

src/gui_x11.c
src/version.c

index 097de5f90e7eb6c9070db8870981fb7152c34664..490844969bc756d359d368853ea11ba8fde51810 100644 (file)
@@ -2296,15 +2296,24 @@ gui_mch_get_color(char_u *name)
     guicolor_T
 gui_mch_get_rgb_color(int r, int g, int b)
 {
-    char       spec[8]; /* space enough to hold "#RRGGBB" */
     XColor     available;
     Colormap   colormap;
 
+/* Using XParseColor() is very slow, put rgb in XColor directly.
+
+    char       spec[8]; // space enough to hold "#RRGGBB"
     vim_snprintf(spec, sizeof(spec), "#%.2x%.2x%.2x", r, g, b);
-    colormap = DefaultColormap(gui.dpy, DefaultScreen(gui.dpy));
     if (XParseColor(gui.dpy, colormap, (char *)spec, &available) != 0
            && XAllocColor(gui.dpy, colormap, &available) != 0)
        return (guicolor_T)available.pixel;
+*/
+    colormap = DefaultColormap(gui.dpy, DefaultScreen(gui.dpy));
+    vim_memset(&available, 0, sizeof(XColor));
+    available.red = r << 8;
+    available.green = g << 8;
+    available.blue = b << 8;
+    if (XAllocColor(gui.dpy, colormap, &available) != 0)
+       return (guicolor_T)available.pixel;
 
     return INVALCOLOR;
 }
index 7f7e1b61fc575b7aa13bf9b46d437e635410d6a9..0e1cdff0d2a071043f7d6a7a698c97fe315e811c 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1800,
 /**/
     1799,
 /**/