-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ZopfliInitHash to: - ZopfliAllocHash - allocate hash memory, - ZopfliResetHash - reset hash values. Allocate Hash outside of ZopfliLZ77Greedy and ZopfliLZ77OptimalRun that pass it further to functions previously allocating them. Do the same for costs malloc'd array. Reason for this change: - the size of malloc doesn't change, - speed up Zopfli*, - fix crash on certain devices**. * speeds up Zopfli (especially on smaller blocks) by reducing amount of sys time from ~7s to 0.1s on x64 Linux for ~5m compression time and from ~1m to 0.1s on ARMv7 Linux for 13m compression time. ** fixes a large amount of iterations crash on some ARM devices that due to architecture or older kernel (not sure which) don't handle too aggressive heap allocation and freeing.
- Loading branch information
1 parent
16e0741
commit 365bda1
Showing
6 changed files
with
59 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,13 +26,26 @@ Author: [email protected] (Jyrki Alakuijala) | |
#define HASH_SHIFT 5 | ||
#define HASH_MASK 32767 | ||
|
||
void ZopfliInitHash(size_t window_size, ZopfliHash* h) { | ||
size_t i; | ||
|
||
h->val = 0; | ||
void ZopfliAllocHash(size_t window_size, ZopfliHash* h) { | ||
h->head = (int*)malloc(sizeof(*h->head) * 65536); | ||
h->prev = (unsigned short*)malloc(sizeof(*h->prev) * window_size); | ||
h->hashval = (int*)malloc(sizeof(*h->hashval) * window_size); | ||
|
||
#ifdef ZOPFLI_HASH_SAME | ||
h->same = (unsigned short*)malloc(sizeof(*h->same) * window_size); | ||
#endif | ||
|
||
#ifdef ZOPFLI_HASH_SAME_HASH | ||
h->head2 = (int*)malloc(sizeof(*h->head2) * 65536); | ||
h->prev2 = (unsigned short*)malloc(sizeof(*h->prev2) * window_size); | ||
h->hashval2 = (int*)malloc(sizeof(*h->hashval2) * window_size); | ||
#endif | ||
} | ||
|
||
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. */ | ||
} | ||
|
@@ -42,17 +55,13 @@ void ZopfliInitHash(size_t window_size, ZopfliHash* h) { | |
} | ||
|
||
#ifdef ZOPFLI_HASH_SAME | ||
h->same = (unsigned short*)malloc(sizeof(*h->same) * window_size); | ||
for (i = 0; i < window_size; i++) { | ||
h->same[i] = 0; | ||
} | ||
#endif | ||
|
||
#ifdef ZOPFLI_HASH_SAME_HASH | ||
h->val2 = 0; | ||
h->head2 = (int*)malloc(sizeof(*h->head2) * 65536); | ||
h->prev2 = (unsigned short*)malloc(sizeof(*h->prev2) * window_size); | ||
h->hashval2 = (int*)malloc(sizeof(*h->hashval2) * window_size); | ||
for (i = 0; i < 65536; i++) { | ||
h->head2[i] = -1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters