summaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-25 22:03:59 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-25 22:03:59 -0700
commit656be88ba3b0db383101449d7d2f09348601d7d7 (patch)
tree03528a96c46ca067372eacb2c9281ed019114063 /match.c
parentaff81beab2bb507a9d421f7e4765dbac4a28b0df (diff)
downloaddartboat-656be88ba3b0db383101449d7d2f09348601d7d7.tar.gz
dartboat-656be88ba3b0db383101449d7d2f09348601d7d7.tar.xz
handle visits memory entirely from match file
Diffstat (limited to 'match.c')
-rw-r--r--match.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/match.c b/match.c
index 977bfe1..edcd405 100644
--- a/match.c
+++ b/match.c
@@ -29,7 +29,7 @@ void leg_free(struct leg *l)
free(l);
}
-void leg_grow_visits(struct leg *l)
+static void leg_grow_visits(struct leg *l)
{
size_t bytes = l->size_visits * sizeof(*l->visits);
l->size_visits *= 2;
@@ -37,6 +37,13 @@ void leg_grow_visits(struct leg *l)
memset((char *)l->visits + bytes, 0, bytes);
}
+struct visit *leg_visit(struct leg *l)
+{
+ if (l->n_visits == l->size_visits)
+ leg_grow_visits(l);
+ return l->visits + l->n_visits++;
+}
+
void leg_undo_visit(struct leg *l)
{
l->rem += l->visits[--l->n_visits].points;
@@ -81,9 +88,7 @@ struct visit *leg_pts_visit(struct leg *l, int pts)
if (l->undone_visits)
leg_clear_first_undone(l);
- if (l->n_visits == l->size_visits)
- leg_grow_visits(l);
- struct visit *v = l->visits + l->n_visits++;
+ struct visit *v = leg_visit(l);
v->points = pts;
l->rem -= pts;
v->rem = l->rem;