From 9edcd68e7ddcdc4deca8c07b5b1c3c59cef13255 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 25 May 2022 00:57:32 -0700 Subject: pregenerate segment names to avoid constant mallocs --- web/Makefile | 2 +- web/web_control.c | 5 ++--- web/web_scoreboard.c | 7 ++----- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'web') diff --git a/web/Makefile b/web/Makefile index 07b7d78..aa2666a 100644 --- a/web/Makefile +++ b/web/Makefile @@ -1,6 +1,6 @@ CC := emcc -CFLAGS += -O3 -Wall -Wextra -Wno-unknown-warning-option -I../ \ +CFLAGS += -O3 -Wall -Wextra -I../ \ -sNO_EXIT_RUNTIME=1 \ -sENVIRONMENT=web \ -sEXPORTED_FUNCTIONS=_main,_malloc,_free \ diff --git a/web/web_control.c b/web/web_control.c index a7a53cf..07d52b1 100644 --- a/web/web_control.c +++ b/web/web_control.c @@ -81,9 +81,8 @@ static void schedule_boat_visit_draws(struct leg *l, struct visit *v, for (int i = 0; i < v->n_darts; ++i) { pts += segment_points(v->darts[i]); - char *seg_name = segment_name(v->darts[i]); - len_str += sprintf(str + len_str, i ? "-%s" : "%s", seg_name); - free(seg_name); + len_str += sprintf(str + len_str, i ? "-%s" : "%s", + segment_name(v->darts[i])); struct ccoords c = v->ccoords[i]; diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index 2e998cc..ed25b33 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -262,12 +262,9 @@ static const char *points_class(int pts) static void buf_darts(char *buf, size_t size, struct visit *v) { char *ptr = buf; - for (int j = 0; j < v->n_darts; ++j) { - char *n = segment_name(v->darts[j]); + for (int j = 0; j < v->n_darts; ++j) ptr += snprintf(ptr, size - (ptr - buf), - j == 0 ? "%s" : "-%s", n); - free(n); - } + j == 0 ? "%s" : "-%s", segment_name(v->darts[j])); } void draw_visits_dense() -- cgit v1.2.3-70-g09d2