From de3170ad81f996f48b3095dcb0bf469cf77b9c35 Mon Sep 17 00:00:00 2001 From: MrKrzYch00 Date: Fri, 22 Apr 2016 20:29:10 +0200 Subject: [PATCH 1/2] Improve hash memory management - Small speed when running a lot of iterations Before: real 13m55.064s user 13m54.610s sys 0m0.180s After: real 13m48.580s user 13m48.555s sys 0m0.010s * tested on Odroid U3 O/C 1.92Ghz, 5000 iterations on old lodepng.cpp sourcecode file. --- src/zopfli/hash.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/zopfli/hash.c b/src/zopfli/hash.c index 3025d1e2..32727ec9 100644 --- a/src/zopfli/hash.c +++ b/src/zopfli/hash.c @@ -46,28 +46,22 @@ void ZopfliResetHash(size_t window_size, ZopfliHash* h) { size_t i; h->val = 0; - for (i = 0; i < 65536; i++) { - h->head[i] = -1; /* -1 indicates no head so far. */ - } - for (i = 0; i < window_size; i++) { - h->prev[i] = i; /* If prev[j] == j, then prev[j] is uninitialized. */ - h->hashval[i] = -1; + memset(h->head, -1, sizeof(*h->head) * 65536); + memset(h->hashval, -1, sizeof(*h->hashval) * window_size); + for (i = 0; i < window_size; ++i) { + h->prev[i] = i; } #ifdef ZOPFLI_HASH_SAME - for (i = 0; i < window_size; i++) { - h->same[i] = 0; - } + memset(h->same, 0, sizeof(*h->same) * window_size); #endif #ifdef ZOPFLI_HASH_SAME_HASH h->val2 = 0; - for (i = 0; i < 65536; i++) { - h->head2[i] = -1; - } - for (i = 0; i < window_size; i++) { + memset(h->head2, -1, sizeof(*h->head2) * 65536); + memset(h->hashval2, -1, sizeof(*h->hashval2) * window_size); + for (i = 0; i < window_size; ++i) { h->prev2[i] = i; - h->hashval2[i] = -1; } #endif } From ec21aff05542c63fee9fcb3ca9a2e01237b0284b Mon Sep 17 00:00:00 2001 From: MrKrzYch00 Date: Fri, 22 Apr 2016 20:39:46 +0200 Subject: [PATCH 2/2] Fix missing comments --- src/zopfli/hash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/zopfli/hash.c b/src/zopfli/hash.c index 32727ec9..3e3da0ef 100644 --- a/src/zopfli/hash.c +++ b/src/zopfli/hash.c @@ -46,10 +46,11 @@ void ZopfliResetHash(size_t window_size, ZopfliHash* h) { size_t i; h->val = 0; + /* -1 indicates no head so far. */ memset(h->head, -1, sizeof(*h->head) * 65536); memset(h->hashval, -1, sizeof(*h->hashval) * window_size); for (i = 0; i < window_size; ++i) { - h->prev[i] = i; + h->prev[i] = i; /* If prev[j] == j, then prev[j] is uninitialized. */ } #ifdef ZOPFLI_HASH_SAME