summaryrefslogtreecommitdiff
path: root/src/gui_x11.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-05-06 19:19:36 +0200
committerBram Moolenaar <Bram@vim.org>2018-05-06 19:19:36 +0200
commit778df2a3cb8b58b07647952c708439acb0b06d17 (patch)
treecf0bb4332cd9af416df0cb364fa4b102843332d0 /src/gui_x11.c
parent85eee130f44a2201d88ca2aeff0af3b11dd75fa9 (diff)
downloadvim-git-778df2a3cb8b58b07647952c708439acb0b06d17.tar.gz
patch 8.0.1800: X11: getting color is slowv8.0.1800
Problem: X11: getting color is slow. Solution: Avoid using sprintf() and XParseColor(), put the RGB values in XColor directly.
Diffstat (limited to 'src/gui_x11.c')
-rw-r--r--src/gui_x11.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/gui_x11.c b/src/gui_x11.c
index 097de5f90..490844969 100644
--- 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;
}