aboutsummaryrefslogtreecommitdiff
path: root/src/render.c
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2022-03-28 00:30:15 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2022-03-28 00:30:15 +0300
commitc251b0d5a905f19498e1d3312041b794e57fd2f8 (patch)
tree79855493ea5e834cdcc68e47d09c6d2ba6f101b7 /src/render.c
parent7bab456f05fa12420d69118e8c78f6e847b89fe7 (diff)
downloadrevela-c251b0d5a905f19498e1d3312041b794e57fd2f8.tar.gz
revela-c251b0d5a905f19498e1d3312041b794e57fd2f8.zip
Little fixes and optimizations
* Don't read image with Magick if it's up to date. * Some memory leaks fixed. There's still are some minor leaks.
Diffstat (limited to 'src/render.c')
-rw-r--r--src/render.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/render.c b/src/render.c
index 79e5245..bc9b8df 100644
--- a/src/render.c
+++ b/src/render.c
@@ -36,16 +36,17 @@ images_walk(struct bstnode *node, void *data)
return true;
}
-static struct roscha_object *
-years_push_new_year(struct roscha_object *years, char *yearstr)
+static inline void
+years_push_new_year(struct roscha_object *years, char *yearstr,
+ struct roscha_object **year, struct roscha_object **albums)
{
- struct roscha_object *year = roscha_object_new(hmap_new_with_cap(8));
- struct roscha_object *albums = roscha_object_new(vector_new_with_cap(8));
- roscha_hmap_set_new(year, "name", (slice_whole(yearstr)));
- roscha_hmap_set(year, "albums", albums);
- roscha_vector_push(years, year);
-
- return year;
+ *year = roscha_object_new(hmap_new_with_cap(8));
+ *albums = roscha_object_new(vector_new_with_cap(8));
+ roscha_hmap_set_new((*year), "name", (slice_whole(yearstr)));
+ roscha_hmap_set(*year, "albums", *albums);
+ roscha_vector_push(years, *year);
+ roscha_object_unref(*year);
+ roscha_object_unref(*albums);
}
static void
@@ -54,15 +55,16 @@ years_push_album(struct roscha_object *years, struct album *album)
struct roscha_object *year;
struct roscha_object *albums;
if (years->vector->len == 0) {
- year = years_push_new_year(years, album->year);
+ years_push_new_year(years, album->year, &years, &albums);
} else {
year = years->vector->values[years->vector->len - 1];
struct roscha_object *yearval = roscha_hmap_get(year, "name");
if (strcmp(yearval->slice.str, album->year)) {
- year = years_push_new_year(years, album->year);
+ years_push_new_year(years, album->year, &year, &albums);
+ } else {
+ albums = roscha_hmap_get(year, "albums");
}
}
- albums = roscha_hmap_get(year, "albums");
roscha_vector_push(albums, album->map);
}