diff options
| author | Paul Eggert | 2013-08-19 13:47:27 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-08-19 13:47:27 -0700 |
| commit | bb566ceafe3230d55923cb3043c3b231e4b9c0f9 (patch) | |
| tree | 813650378c30dc75d9493acd1909a868512859bc /src | |
| parent | 453f40228f8ff3d43665f5bf008b117bf9b9a7dc (diff) | |
| download | emacs-bb566ceafe3230d55923cb3043c3b231e4b9c0f9.tar.gz emacs-bb566ceafe3230d55923cb3043c3b231e4b9c0f9.zip | |
* image.c: Shrink memory needed for animation cache.
(SIGNATURE_DIGESTSIZE): New constant.
(struct animation_cache): Make 'signature' a fixed size array of bytes.
(imagemagick_create_cache): Copy the signature. This saves
several KB of memory that ImageMagick wastes per signature.
Don't bother updating the update_time, as the caller does that now.
(imagemagick_prune_animation_cache): Don't destroy the signature, as
it's a fixed size struct member now.
(imagemagick_get_animation_cache): Always destroy the signature,
as it's now imagemagick_create_cache's responsibility to copy it.
Avoid duplicate calls to strcmp and to imagemagick_create_cache,
and use memcmp rather than strcmp.
eassert that ImageMagick returns a signature of the specified length.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 16 | ||||
| -rw-r--r-- | src/image.c | 36 |
2 files changed, 34 insertions, 18 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 2171f2b8748..d0bafd3914e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,19 @@ | |||
| 1 | 2013-08-19 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | * image.c: Shrink memory needed for animation cache. | ||
| 4 | (SIGNATURE_DIGESTSIZE): New constant. | ||
| 5 | (struct animation_cache): Make 'signature' a fixed size array of bytes. | ||
| 6 | (imagemagick_create_cache): Copy the signature. This saves | ||
| 7 | several KB of memory that ImageMagick wastes per signature. | ||
| 8 | Don't bother updating the update_time, as the caller does that now. | ||
| 9 | (imagemagick_prune_animation_cache): Don't destroy the signature, as | ||
| 10 | it's a fixed size struct member now. | ||
| 11 | (imagemagick_get_animation_cache): Always destroy the signature, | ||
| 12 | as it's now imagemagick_create_cache's responsibility to copy it. | ||
| 13 | Avoid duplicate calls to strcmp and to imagemagick_create_cache, | ||
| 14 | and use memcmp rather than strcmp. | ||
| 15 | eassert that ImageMagick returns a signature of the specified length. | ||
| 16 | |||
| 1 | 2013-08-19 Lars Magne Ingebrigtsen <larsi@gnus.org> | 17 | 2013-08-19 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 18 | ||
| 3 | * image.c (imagemagick_get_animation_cache): Don't segfault on | 19 | * image.c (imagemagick_get_animation_cache): Don't segfault on |
diff --git a/src/image.c b/src/image.c index 7a6323ad332..4970d40af33 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -7876,13 +7876,17 @@ imagemagick_filename_hint (Lisp_Object spec, char hint_buffer[MaxTextExtent]) | |||
| 7876 | separate from the image cache, because the images may be scaled | 7876 | separate from the image cache, because the images may be scaled |
| 7877 | before display. */ | 7877 | before display. */ |
| 7878 | 7878 | ||
| 7879 | /* Size of ImageMagick image signatures, in bytes. It's SHA-256 as a | ||
| 7880 | hex string, so it's 256 bits represented via 4 bits per byte. */ | ||
| 7881 | enum { SIGNATURE_DIGESTSIZE = 256 / 4 }; | ||
| 7882 | |||
| 7879 | struct animation_cache | 7883 | struct animation_cache |
| 7880 | { | 7884 | { |
| 7881 | char *signature; | ||
| 7882 | MagickWand *wand; | 7885 | MagickWand *wand; |
| 7883 | int index; | 7886 | int index; |
| 7884 | EMACS_TIME update_time; | 7887 | EMACS_TIME update_time; |
| 7885 | struct animation_cache *next; | 7888 | struct animation_cache *next; |
| 7889 | char signature[SIGNATURE_DIGESTSIZE]; | ||
| 7886 | }; | 7890 | }; |
| 7887 | 7891 | ||
| 7888 | static struct animation_cache *animation_cache = NULL; | 7892 | static struct animation_cache *animation_cache = NULL; |
| @@ -7891,11 +7895,10 @@ static struct animation_cache * | |||
| 7891 | imagemagick_create_cache (char *signature) | 7895 | imagemagick_create_cache (char *signature) |
| 7892 | { | 7896 | { |
| 7893 | struct animation_cache *cache = xmalloc (sizeof *cache); | 7897 | struct animation_cache *cache = xmalloc (sizeof *cache); |
| 7894 | cache->signature = signature; | ||
| 7895 | cache->wand = 0; | 7898 | cache->wand = 0; |
| 7896 | cache->index = 0; | 7899 | cache->index = 0; |
| 7897 | cache->next = 0; | 7900 | cache->next = 0; |
| 7898 | cache->update_time = current_emacs_time (); | 7901 | memcpy (cache->signature, signature, SIGNATURE_DIGESTSIZE); |
| 7899 | return cache; | 7902 | return cache; |
| 7900 | } | 7903 | } |
| 7901 | 7904 | ||
| @@ -7914,7 +7917,6 @@ imagemagick_prune_animation_cache (void) | |||
| 7914 | pcache = &cache->next; | 7917 | pcache = &cache->next; |
| 7915 | else | 7918 | else |
| 7916 | { | 7919 | { |
| 7917 | DestroyString (cache->signature); | ||
| 7918 | if (cache->wand) | 7920 | if (cache->wand) |
| 7919 | DestroyMagickWand (cache->wand); | 7921 | DestroyMagickWand (cache->wand); |
| 7920 | *pcache = cache->next; | 7922 | *pcache = cache->next; |
| @@ -7928,24 +7930,22 @@ imagemagick_get_animation_cache (MagickWand *wand) | |||
| 7928 | { | 7930 | { |
| 7929 | char *signature = MagickGetImageSignature (wand); | 7931 | char *signature = MagickGetImageSignature (wand); |
| 7930 | struct animation_cache *cache; | 7932 | struct animation_cache *cache; |
| 7933 | struct animation_cache **pcache = &animation_cache; | ||
| 7931 | 7934 | ||
| 7935 | eassert (strlen (signature) == SIGNATURE_DIGESTSIZE); | ||
| 7932 | imagemagick_prune_animation_cache (); | 7936 | imagemagick_prune_animation_cache (); |
| 7933 | cache = animation_cache; | ||
| 7934 | 7937 | ||
| 7935 | if (! cache) | 7938 | while (1) |
| 7936 | { | 7939 | { |
| 7937 | animation_cache = imagemagick_create_cache (signature); | 7940 | cache = *pcache; |
| 7938 | return animation_cache; | 7941 | if (! cache) |
| 7939 | } | 7942 | { |
| 7940 | 7943 | *pcache = cache = imagemagick_create_cache (signature); | |
| 7941 | while (strcmp (signature, cache->signature) && | 7944 | break; |
| 7942 | cache->next) | 7945 | } |
| 7943 | cache = cache->next; | 7946 | if (memcmp (signature, cache->signature, SIGNATURE_DIGESTSIZE) == 0) |
| 7944 | 7947 | break; | |
| 7945 | if (strcmp (signature, cache->signature)) | 7948 | pcache = &cache->next; |
| 7946 | { | ||
| 7947 | cache->next = imagemagick_create_cache (signature); | ||
| 7948 | return cache->next; | ||
| 7949 | } | 7949 | } |
| 7950 | 7950 | ||
| 7951 | DestroyString (signature); | 7951 | DestroyString (signature); |