aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--src/render.c26
-rw-r--r--src/site.c17
2 files changed, 25 insertions, 18 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);
}
diff --git a/src/site.c b/src/site.c
index 058da13..4c87c9d 100644
--- a/src/site.c
+++ b/src/site.c
@@ -130,6 +130,7 @@ images_walk(struct bstnode *node, void *data)
struct image *image = node->value;
struct stat dstat;
struct timespec ddate = { .tv_sec = image->tstamp, .tv_nsec = 0 };
+ int imgupdate, thumbupdate;
char htmlpath[PATH_MAX];
const char *base = rbasename(image->dst);
@@ -138,18 +139,22 @@ images_walk(struct bstnode *node, void *data)
if (!nmkdir(image->dst, &dstat, site->dry_run)) return false;
- if (!site->dry_run) {
+ imgupdate = file_is_uptodate(image->dst_image, &image->modtime);
+ if (imgupdate == -1) goto magick_fail;
+ thumbupdate = file_is_uptodate(image->dst_image, &image->modtime);
+ if (thumbupdate == -1) goto magick_fail;
+ if (!site->dry_run && (!imgupdate || !thumbupdate)) {
TRYWAND(site->wand, MagickReadImage(site->wand, image->source));
}
- if (!optimize_image(site->wand, image->dst_image, &site->config->images,
- &image->modtime, site->dry_run)) {
+ if (!imgupdate && !optimize_image(site->wand, image->dst_image,
+ &site->config->images, &image->modtime, site->dry_run)) {
goto magick_fail;
}
- if (!optimize_image(site->wand, image->dst_thumb, &site->config->thumbnails,
- &image->modtime, site->dry_run)) {
+ if (!thumbupdate && !optimize_image(site->wand, image->dst_thumb,
+ &site->config->thumbnails, &image->modtime, site->dry_run)) {
goto magick_fail;
}
- if (!site->dry_run) {
+ if (!site->dry_run && (!imgupdate || !thumbupdate)) {
MagickRemoveImage(site->wand);
}