Skip to content

Commit

Permalink
demos/plplay: avoid re-saving unmodified cache
Browse files Browse the repository at this point in the history
By comparing signature before and after loading.
  • Loading branch information
haasn committed Nov 18, 2023
1 parent 452377d commit 2385b36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions demos/plplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ static void uninit(struct plplay *p)
pl_icc_close(&p->icc);

if (p->cache) {
FILE *file = fopen(p->cache_file, "wb");
if (file) {
pl_cache_save_file(p->cache, file);
fclose(file);
if (pl_cache_signature(p->cache) != p->cache_sig) {
FILE *file = fopen(p->cache_file, "wb");
if (file) {
pl_cache_save_file(p->cache, file);
fclose(file);
}
}
pl_cache_destroy(&p->cache);
}
Expand Down Expand Up @@ -738,6 +740,7 @@ int main(int argc, char *argv[])
FILE *file = fopen(p->cache_file, "rb");
if (file) {
pl_cache_load_file(p->cache, file);
p->cache_sig = pl_cache_signature(p->cache);
fclose(file);
}
}
Expand Down
1 change: 1 addition & 0 deletions demos/plplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct plplay {
pl_renderer renderer;
pl_queue queue;
pl_cache cache;
uint64_t cache_sig;

// libav*
AVFormatContext *format;
Expand Down

0 comments on commit 2385b36

Please sign in to comment.