Skip to content

Commit e51e02a

Browse files
committed
TileGrid: avoid obj_is_type calls in loop
.. and move the common cases first. 3.91fps.
1 parent f3f2af6 commit e51e02a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

shared-module/displayio/TileGrid.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self,
557557
const int x_subgrid_start = x_pixel_start % tile_width;
558558
const int x_grid_start = x_pixel_start / tile_width;
559559

560+
const mp_obj_type_t *pixel_shader_type = mp_obj_get_type(self->pixel_shader);
561+
560562
int old_tile = 0, tile_row = 0, tile_col = 0;
561563
for (input_pixel.y = start_y; input_pixel.y < end_y; ++input_pixel.y) {
562564
int16_t row_start = start + (input_pixel.y - start_y + y_shift) * y_stride; // in pixels
@@ -617,12 +619,12 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self,
617619
input_pixel.pixel = get_pixel_func(self->bitmap, input_pixel.tile_x, input_pixel.tile_y);
618620

619621
output_pixel.opaque = true;
620-
if (self->pixel_shader == mp_const_none) {
621-
output_pixel.pixel = input_pixel.pixel;
622-
} else if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) {
622+
if (pixel_shader_type == &displayio_palette_type) {
623623
output_pixel.opaque = displayio_palette_get_color(self->pixel_shader, colorspace, input_pixel.pixel, &output_pixel.pixel);
624-
} else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) {
624+
} else if (pixel_shader_type == &displayio_colorconverter_type) {
625625
displayio_colorconverter_convert(self->pixel_shader, colorspace, &input_pixel, &output_pixel);
626+
} else {
627+
output_pixel.pixel = input_pixel.pixel;
626628
}
627629
pixel_changed = false;
628630
}

0 commit comments

Comments
 (0)