diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-02-24 17:18:08 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-02-24 17:18:08 +0100 |
commit | 1232f3482b272fbe8986c9677b529ec7b6cb0183 (patch) | |
tree | 7c17e8177d2aef5df4a80344ec4d0c64ca616355 /src/blogc-make | |
parent | 6bc34603d772fedcd90ffd0d198622e6582a44b1 (diff) | |
download | blogc-1232f3482b272fbe8986c9677b529ec7b6cb0183.tar.gz blogc-1232f3482b272fbe8986c9677b529ec7b6cb0183.tar.bz2 blogc-1232f3482b272fbe8986c9677b529ec7b6cb0183.zip |
make: do not run stat twice for regular files when copying
Diffstat (limited to 'src/blogc-make')
-rw-r--r-- | src/blogc-make/ctx.c | 38 | ||||
-rw-r--r-- | src/blogc-make/ctx.h | 3 | ||||
-rw-r--r-- | src/blogc-make/rules.c | 16 |
3 files changed, 31 insertions, 26 deletions
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c index ee050a4..de92fcf 100644 --- a/src/blogc-make/ctx.c +++ b/src/blogc-make/ctx.c @@ -24,7 +24,7 @@ bm_filectx_t* -bm_filectx_new(bm_ctx_t *ctx, const char *filename) +bm_filectx_new(bm_ctx_t *ctx, const char *filename, struct stat *st) { if (ctx == NULL || filename == NULL) return NULL; @@ -36,19 +36,23 @@ bm_filectx_new(bm_ctx_t *ctx, const char *filename) rv->path = f; rv->short_path = bc_strdup(filename); - struct stat buf; + if (st == NULL) { + struct stat buf; - if (0 != stat(f, &buf)) { - rv->tv_sec = 0; - rv->tv_nsec = 0; - rv->readable = false; - } - else { - rv->tv_sec = buf.st_mtim_tv_sec; - rv->tv_nsec = buf.st_mtim_tv_nsec; - rv->readable = true; + if (0 != stat(f, &buf)) { + rv->tv_sec = 0; + rv->tv_nsec = 0; + rv->readable = false; + return rv; + } + + st = &buf; } + // if st isn't NULL the file exists for sure + rv->tv_sec = st->st_mtim_tv_sec; + rv->tv_nsec = st->st_mtim_tv_nsec; + rv->readable = true; return rv; } @@ -89,7 +93,7 @@ bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename) return l; } - l = bc_slist_append(l, bm_filectx_new(ctx, filename)); + l = bc_slist_append(l, bm_filectx_new(ctx, filename, &buf)); free(f); return l; } @@ -196,7 +200,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0, rv->settings = settings; char *real_filename = realpath(settings_file, NULL); - rv->settings_fctx = bm_filectx_new(rv, real_filename); + rv->settings_fctx = bm_filectx_new(rv, real_filename, NULL); rv->root_dir = realpath(dirname(real_filename), NULL); free(real_filename); @@ -218,10 +222,10 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0, char *main_template = bc_strdup_printf("%s/%s", template_dir, bc_trie_lookup(settings->settings, "main_template")); - rv->main_template_fctx = bm_filectx_new(rv, main_template); + rv->main_template_fctx = bm_filectx_new(rv, main_template, NULL); free(main_template); - rv->atom_template_fctx = bm_filectx_new(rv, atom_template); + rv->atom_template_fctx = bm_filectx_new(rv, atom_template, NULL); free(atom_template); const char *content_dir = bc_trie_lookup(settings->settings, "content_dir"); @@ -234,7 +238,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0, char *f = bc_strdup_printf("%s/%s/%s%s", content_dir, post_prefix, settings->posts[i], source_ext); rv->posts_fctx = bc_slist_append(rv->posts_fctx, - bm_filectx_new(rv, f)); + bm_filectx_new(rv, f, NULL)); free(f); } } @@ -245,7 +249,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0, char *f = bc_strdup_printf("%s/%s%s", content_dir, settings->pages[i], source_ext); rv->pages_fctx = bc_slist_append(rv->pages_fctx, - bm_filectx_new(rv, f)); + bm_filectx_new(rv, f, NULL)); free(f); } } diff --git a/src/blogc-make/ctx.h b/src/blogc-make/ctx.h index 1c9d8b0..3f70ead 100644 --- a/src/blogc-make/ctx.h +++ b/src/blogc-make/ctx.h @@ -9,6 +9,7 @@ #ifndef _MAKE_CTX_H #define _MAKE_CTX_H +#include <sys/stat.h> #include <stdbool.h> #include <time.h> #include "settings.h" @@ -63,7 +64,7 @@ typedef struct { bc_slist_t *copy_fctx; } bm_ctx_t; -bm_filectx_t* bm_filectx_new(bm_ctx_t *ctx, const char *filename); +bm_filectx_t* bm_filectx_new(bm_ctx_t *ctx, const char *filename, struct stat *st); bc_slist_t* bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename); bool bm_filectx_changed(bm_filectx_t *ctx, time_t *tv_sec, long *tv_nsec); void bm_filectx_reload(bm_filectx_t *ctx); diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c index 2633d04..8a0558b 100644 --- a/src/blogc-make/rules.c +++ b/src/blogc-make/rules.c @@ -52,7 +52,7 @@ index_outputlist(bm_ctx_t *ctx) char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir, is_index ? "" : "/", is_index ? "" : index_prefix, html_ext); - rv = bc_slist_append(rv, bm_filectx_new(ctx, f)); + rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL)); free(f); return rv; } @@ -109,7 +109,7 @@ atom_outputlist(bm_ctx_t *ctx) const char *atom_ext = bc_trie_lookup(ctx->settings->settings, "atom_ext"); char *f = bc_strdup_printf("%s/%s%s", ctx->short_output_dir, atom_prefix, atom_ext); - rv = bc_slist_append(rv, bm_filectx_new(ctx, f)); + rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL)); free(f); return rv; } @@ -167,7 +167,7 @@ atom_tags_outputlist(bm_ctx_t *ctx) for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) { char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir, atom_prefix, ctx->settings->tags[i], atom_ext); - rv = bc_slist_append(rv, bm_filectx_new(ctx, f)); + rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL)); free(f); } return rv; @@ -239,7 +239,7 @@ pagination_outputlist(bm_ctx_t *ctx) for (size_t i = 0; i < pages; i++) { char *f = bc_strdup_printf("%s/%s/%d%s", ctx->short_output_dir, pagination_prefix, i + 1, html_ext); - rv = bc_slist_append(rv, bm_filectx_new(ctx, f)); + rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL)); free(f); } return rv; @@ -301,7 +301,7 @@ posts_outputlist(bm_ctx_t *ctx) for (size_t i = 0; ctx->settings->posts[i] != NULL; i++) { char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir, post_prefix, ctx->settings->posts[i], html_ext); - rv = bc_slist_append(rv, bm_filectx_new(ctx, f)); + rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL)); free(f); } return rv; @@ -362,7 +362,7 @@ tags_outputlist(bm_ctx_t *ctx) for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) { char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir, tag_prefix, ctx->settings->tags[i], html_ext); - rv = bc_slist_append(rv, bm_filectx_new(ctx, f)); + rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL)); free(f); } return rv; @@ -429,7 +429,7 @@ pages_outputlist(bm_ctx_t *ctx) char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir, is_index ? "" : "/", is_index ? "" : ctx->settings->pages[i], html_ext); - rv = bc_slist_append(rv, bm_filectx_new(ctx, f)); + rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL)); free(f); } return rv; @@ -487,7 +487,7 @@ copy_outputlist(bm_ctx_t *ctx) for (bc_slist_t *s = ctx->copy_fctx; s != NULL; s = s->next) { char *f = bc_strdup_printf("%s/%s", ctx->short_output_dir, ((bm_filectx_t*) s->data)->short_path); - rv = bc_slist_append(rv, bm_filectx_new(ctx, f)); + rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL)); free(f); } return rv; |