Mercurial > vim
comparison src/gui_x11.c @ 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 | ac42c4b11dbc |
children | eb264a775071 |
comparison
equal
deleted
inserted
replaced
13857:e751b5c9dff3 | 13858:245c053021d3 |
---|---|
2294 * Return INVALCOLOR for error. | 2294 * Return INVALCOLOR for error. |
2295 */ | 2295 */ |
2296 guicolor_T | 2296 guicolor_T |
2297 gui_mch_get_rgb_color(int r, int g, int b) | 2297 gui_mch_get_rgb_color(int r, int g, int b) |
2298 { | 2298 { |
2299 char spec[8]; /* space enough to hold "#RRGGBB" */ | |
2300 XColor available; | 2299 XColor available; |
2301 Colormap colormap; | 2300 Colormap colormap; |
2302 | 2301 |
2302 /* Using XParseColor() is very slow, put rgb in XColor directly. | |
2303 | |
2304 char spec[8]; // space enough to hold "#RRGGBB" | |
2303 vim_snprintf(spec, sizeof(spec), "#%.2x%.2x%.2x", r, g, b); | 2305 vim_snprintf(spec, sizeof(spec), "#%.2x%.2x%.2x", r, g, b); |
2304 colormap = DefaultColormap(gui.dpy, DefaultScreen(gui.dpy)); | |
2305 if (XParseColor(gui.dpy, colormap, (char *)spec, &available) != 0 | 2306 if (XParseColor(gui.dpy, colormap, (char *)spec, &available) != 0 |
2306 && XAllocColor(gui.dpy, colormap, &available) != 0) | 2307 && XAllocColor(gui.dpy, colormap, &available) != 0) |
2308 return (guicolor_T)available.pixel; | |
2309 */ | |
2310 colormap = DefaultColormap(gui.dpy, DefaultScreen(gui.dpy)); | |
2311 vim_memset(&available, 0, sizeof(XColor)); | |
2312 available.red = r << 8; | |
2313 available.green = g << 8; | |
2314 available.blue = b << 8; | |
2315 if (XAllocColor(gui.dpy, colormap, &available) != 0) | |
2307 return (guicolor_T)available.pixel; | 2316 return (guicolor_T)available.pixel; |
2308 | 2317 |
2309 return INVALCOLOR; | 2318 return INVALCOLOR; |
2310 } | 2319 } |
2311 | 2320 |