From 8166287e0c30274d901b401213ed2165ea2604bd Mon Sep 17 00:00:00 2001 From: leonmavr <0xleo.git@gmail.com> Date: Sat, 21 Sep 2024 16:33:46 +0200 Subject: [PATCH] shorten a copy with memcpy --- src/quad.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/quad.c b/src/quad.c index 8484891..e13e045 100644 --- a/src/quad.c +++ b/src/quad.c @@ -282,22 +282,15 @@ static void node_merge(node_t* node) { int ipoint = 0; for (int i = 0; i < 4; ++i) { for (int j = 0; j < children[i]->count; ++j) { - node->points[ipoint].x = children[i]->points[j].x; - node->points[ipoint].y = children[i]->points[j].y; - node->points[ipoint].id = children[i]->points[j].id; - ipoint++; + memcpy(&node->points[ipoint++], &children[i]->points[j], sizeof(node->points[0])); (node->count)++; } } - free(node->nw); - free(node->nw->points); - free(node->ne); - free(node->ne->points); - free(node->se); - free(node->se->points); - free(node->sw); - free(node->sw->points); - // make the current node a leaf + for (int i = 0; i < 4; ++i) { + free(children[i]); + free(children[i]->points); + } + // set children to NULL to make current node a leaf node->nw = node->ne = node->se = node->sw = NULL; } }