To: vim_dev@googlegroups.com Subject: Patch 8.0.1800 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1800 Problem: X11: getting color is slow. Solution: Avoid using sprintf() and XParseColor(), put the RGB values in XColor directly. Files: src/gui_x11.c *** ../vim-8.0.1799/src/gui_x11.c 2018-02-10 18:45:21.060822215 +0100 --- src/gui_x11.c 2018-05-06 19:02:28.516945532 +0200 *************** *** 2296,2310 **** 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; 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; return INVALCOLOR; } --- 2296,2319 ---- guicolor_T gui_mch_get_rgb_color(int r, int g, int b) { 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); 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; } *** ../vim-8.0.1799/src/version.c 2018-05-06 17:32:09.512088409 +0200 --- src/version.c 2018-05-06 19:17:58.227048545 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1800, /**/ -- ARTHUR: Be quiet! DENNIS: Well you can't expect to wield supreme executive power just 'cause some watery tart threw a sword at you! ARTHUR: Shut up! DENNIS: I mean, if I went around sayin' I was an empereror just because some moistened bint had lobbed a scimitar at me they'd put me away! The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///