Skip to content

Commit 0f0dba3

Browse files
committed
Cleanups for func pointers
1 parent d0de0af commit 0f0dba3

5 files changed

Lines changed: 23 additions & 30 deletions

File tree

gfx/drivers/ctr_gfx.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,14 @@ static int ctr_font_get_message_width(void* data, const char* msg,
489489
int delta_x = 0;
490490
const struct font_glyph* glyph_q = NULL;
491491
ctr_font_t* font = (ctr_font_t*)data;
492+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
493+
= font->font_driver->get_glyph;
494+
void *font_data = font->font_data;
492495

493496
if (!font)
494497
return 0;
495498

496-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
499+
glyph_q = get_glyph(font_data, '?');
497500

498501
for (i = 0; i < msg_len; i++)
499502
{
@@ -507,8 +510,7 @@ static int ctr_font_get_message_width(void* data, const char* msg,
507510

508511

509512
/* Do something smarter here ... */
510-
if (!(glyph =
511-
font->font_driver->get_glyph(font->font_data, code)))
513+
if (!(glyph = get_glyph(font_data, code)))
512514
if (!(glyph = glyph_q))
513515
continue;
514516

@@ -539,6 +541,9 @@ static void ctr_font_render_line(
539541
int delta_y = 0;
540542
int x = roundf(pos_x * width);
541543
int y = roundf((1.0f - pos_y) * height);
544+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
545+
= font->font_driver->get_glyph;
546+
void *font_data = font->font_data;
542547

543548
/* For right/center alignment, compute width with a lightweight pass
544549
* that only accumulates advance_x — avoids the redundant glyph lookups
@@ -552,7 +557,7 @@ static void ctr_font_render_line(
552557
{
553558
const struct font_glyph *glyph;
554559
uint32_t code = utf8_walk(&scan);
555-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
560+
if (!(glyph = get_glyph(font_data, code)))
556561
if (!(glyph = glyph_q))
557562
continue;
558563
width_accum += glyph->advance_x;
@@ -581,8 +586,7 @@ static void ctr_font_render_line(
581586
i += skip - 1;
582587

583588
/* Do something smarter here ... */
584-
if (!(glyph =
585-
font->font_driver->get_glyph(font->font_data, code)))
589+
if (!(glyph = get_glyph(font_data, code)))
586590
if (!(glyph = glyph_q))
587591
continue;
588592

@@ -679,9 +683,12 @@ static void ctr_font_render_message(
679683
{
680684
float line_height;
681685
struct font_line_metrics *line_metrics = NULL;
682-
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
686+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
687+
= font->font_driver->get_glyph;
688+
void *font_data = font->font_data;
689+
const struct font_glyph* glyph_q = get_glyph(font_data, '?');
683690
int lines = 0;
684-
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
691+
font->font_driver->get_line_metrics(font_data, &line_metrics);
685692
line_height = (float)line_metrics->height * scale / (float)height;
686693
for (;;)
687694
{

gfx/drivers/d3d10.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,6 @@ static int d3d10_font_get_message_width(void* data,
903903
int delta_x = 0;
904904
const struct font_glyph* glyph_q = NULL;
905905
d3d10_font_t* font = (d3d10_font_t*)data;
906-
/* Hoist function pointer and data pointer out of the loop to avoid
907-
* repeated dependent loads through font->font_driver->get_glyph. */
908906
const struct font_glyph* (*get_glyph)(void*, uint32_t)
909907
= font->font_driver->get_glyph;
910908
void *font_data = font->font_data;
@@ -956,11 +954,9 @@ static void d3d10_font_render_line(
956954
const char* msg_end = msg + msg_len;
957955
int x = pre_x;
958956
int y = roundf((1.0 - pos_y) * height);
959-
/* Hoist function pointer and data pointer out of the loop to avoid
960-
* repeated dependent loads through font->font_driver->get_glyph. */
961957
const struct font_glyph* (*get_glyph)(void*, uint32_t)
962-
= font->font_driver->get_glyph;
963-
void *font_data = font->font_data;
958+
= font->font_driver->get_glyph;
959+
void *font_data = font->font_data;
964960

965961
if (d3d10->sprites.offset + msg_len > (unsigned)d3d10->sprites.capacity)
966962
d3d10->sprites.offset = 0;

gfx/drivers/d3d11.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,6 @@ static int d3d11_font_get_message_width(void* data, const char* msg, size_t msg_
10361036
int delta_x = 0;
10371037
const struct font_glyph* glyph_q = NULL;
10381038
d3d11_font_t* font = (d3d11_font_t*)data;
1039-
/* Hoist function pointer and data pointer out of the loop to avoid
1040-
* repeated dependent loads through font->font_driver->get_glyph. */
10411039
const struct font_glyph* (*get_glyph)(void*, uint32_t)
10421040
= font->font_driver->get_glyph;
10431041
void *font_data = font->font_data;
@@ -1090,9 +1088,6 @@ static void d3d11_font_render_line(
10901088
d3d11_sprite_t *v = NULL;
10911089
int x = pre_x;
10921090
int y = roundf((1.0f - pos_y) * height);
1093-
1094-
/* Hoist function pointer and data pointer out of the loop to avoid
1095-
* repeated dependent loads through font->font_driver->get_glyph. */
10961091
const struct font_glyph* (*get_glyph)(void*, uint32_t)
10971092
= font->font_driver->get_glyph;
10981093
void *font_data = font->font_data;
@@ -1237,7 +1232,10 @@ static void d3d11_font_render_message(
12371232
struct font_line_metrics *line_metrics = NULL;
12381233
int lines = 0;
12391234
int x = roundf(pos_x * width);
1240-
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
1235+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
1236+
= font->font_driver->get_glyph;
1237+
void *font_data = font->font_data;
1238+
const struct font_glyph* glyph_q = get_glyph(font_data, '?');
12411239
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
12421240
line_height = line_metrics->height * scale / height;
12431241
for (;;)

gfx/drivers/d3d12.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,6 @@ static int d3d12_font_get_message_width(void* data,
13621362
int delta_x = 0;
13631363
const struct font_glyph* glyph_q = NULL;
13641364
d3d12_font_t* font = (d3d12_font_t*)data;
1365-
/* Hoist function pointer and data pointer out of the loop to avoid
1366-
* repeated dependent loads through font->font_driver->get_glyph. */
13671365
const struct font_glyph* (*get_glyph)(void*, uint32_t);
13681366
void *font_data;
13691367

@@ -1419,8 +1417,6 @@ static void d3d12_font_render_line(
14191417
d3d12_sprite_t* vbo_start = NULL;
14201418
int x = pre_x;
14211419
int y = roundf((1.0 - pos_y) * height);
1422-
/* Hoist function pointer and data pointer out of the loop to avoid
1423-
* repeated dependent loads through font->font_driver->get_glyph. */
14241420
const struct font_glyph* (*get_glyph)(void*, uint32_t)
14251421
= font->font_driver->get_glyph;
14261422
void *font_data = font->font_data;

gfx/drivers/vulkan.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,11 +2052,9 @@ static int vulkan_font_get_message_width(void *data, const char *msg,
20522052
vulkan_raster_t *font = (vulkan_raster_t*)data;
20532053
const char* msg_end = msg + msg_len;
20542054
int delta_x = 0;
2055-
/* Hoist function pointer and data pointer out of the loop to avoid
2056-
* repeated dependent loads through font->font_driver->get_glyph. */
20572055
const struct font_glyph* (*get_glyph)(void*, uint32_t)
2058-
= font->font_driver->get_glyph;
2059-
void *font_data = font->font_data;
2056+
= font->font_driver->get_glyph;
2057+
void *font_data = font->font_data;
20602058

20612059
if ( !font
20622060
|| !font->font_driver
@@ -2108,8 +2106,6 @@ static void vulkan_font_render_line(vk_t *vk,
21082106
int y = roundf((1.0f - pos_y) * vk->vp.height);
21092107
int delta_x = 0;
21102108
int delta_y = 0;
2111-
/* Hoist function pointer and data pointer out of the loop to avoid
2112-
* repeated dependent loads through font->font_driver->get_glyph. */
21132109
const struct font_glyph* (*get_glyph)(void*, uint32_t)
21142110
= font->font_driver->get_glyph;
21152111
void *font_data = font->font_data;

0 commit comments

Comments
 (0)