Inline to_color for an easy performance boost

This commit is contained in:
Kovid Goyal
2017-08-26 10:52:24 +05:30
parent 7041616837
commit 4ce9f550ac
3 changed files with 14 additions and 15 deletions

View File

@@ -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 {{{

View File

@@ -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);

View File

@@ -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;