changeset 13858:245c053021d3 v8.0.1800

patch 8.0.1800: X11: getting color is slow commit https://github.com/vim/vim/commit/778df2a3cb8b58b07647952c708439acb0b06d17 Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 6 19:19:36 2018 +0200 patch 8.0.1800: X11: getting color is slow Problem: X11: getting color is slow. Solution: Avoid using sprintf() and XParseColor(), put the RGB values in XColor directly.
author Christian Brabandt <cb@256bit.org>
date Sun, 06 May 2018 19:30:05 +0200
parents e751b5c9dff3
children be340a68650d
files src/gui_x11.c src/version.c
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/gui_x11.c
+++ b/src/gui_x11.c
@@ -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;
 }
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1800,
+/**/
     1799,
 /**/
     1798,