From 4ce9f550ac383ad3cb267e9963893199448eef1e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 26 Aug 2017 10:52:24 +0530 Subject: [PATCH] Inline to_color for an easy performance boost --- kitty/colors.c | 14 -------------- kitty/data-types.h | 1 - kitty/sprites.c | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/kitty/colors.c b/kitty/colors.c index 73e06445c..00058def0 100644 --- a/kitty/colors.c +++ b/kitty/colors.c @@ -133,20 +133,6 @@ set_color(ColorProfile *self, PyObject *args) { } -uint32_t -to_color(ColorProfile *self, uint32_t entry, uint32_t defval) { - unsigned int t = entry & 0xFF, r; - switch(t) { - case 1: - r = (entry >> 8) & 0xff; - return self->color_table[r]; - case 2: - return entry >> 8; - default: - return defval; - } -} - // Boilerplate {{{ diff --git a/kitty/data-types.h b/kitty/data-types.h index 69e6ff5a3..f0feafd1f 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -330,7 +330,6 @@ Cursor* cursor_copy(Cursor*); void cursor_copy_to(Cursor *src, Cursor *dest); void cursor_reset_display_attrs(Cursor*); bool update_cell_range_data(ScreenModes *modes, SpriteMap *, Line *, unsigned int, unsigned int, ColorProfile *, const uint32_t, const uint32_t, unsigned int *); -uint32_t to_color(ColorProfile *, uint32_t, uint32_t); PyObject* line_text_at(char_type, combining_type); void line_clear_text(Line *self, unsigned int at, unsigned int num, int ch); diff --git a/kitty/sprites.c b/kitty/sprites.c index 7ae1e5845..f04274657 100644 --- a/kitty/sprites.c +++ b/kitty/sprites.c @@ -139,6 +139,20 @@ position_for(SpriteMap *self, PyObject *args) { return Py_BuildValue("III", pos->x, pos->y, pos->z); } +static inline uint32_t +to_color(ColorProfile *self, uint32_t entry, uint32_t defval) { + unsigned int t = entry & 0xFF, r; + switch(t) { + case 1: + r = (entry >> 8) & 0xff; + return self->color_table[r]; + case 2: + return entry >> 8; + default: + return defval; + } +} + bool update_cell_range_data(ScreenModes *modes, SpriteMap *self, Line *line, unsigned int xstart, unsigned int xmax, ColorProfile *color_profile, const uint32_t default_bg, const uint32_t default_fg, unsigned int *data) { SpritePosition *sp;