Caching icon theme information
mclasen at redhat.com
Wed Oct 13 23:17:31 EEST 2004
Back in May, Owen Taylor proposed  caching scheme for icon theme
information, to reduce the amount of stating and disk seeking at
application startup, and to reduce the memory overhead if each app
allocates all the icon theme data separately.
The proposal is to keep the information about the icons in the
directory tree below each icon theme directory in an mmap()able
cache file (There is basically one cache file per index.theme file).
The cache doesn't try to hold all information from the index.theme files
that you would need to do lookups; it turns out that with the icon theme
specification, this isn't even sensible - you can install a
and chances how lookup happens for icons in /usr/share/icons/Bluecurve.
We would like to propose the cache file format as an appendix to the
icon theme specification. One thing which still needs to be investigated
is caching of the actual image data; the file format is has an
IMAGE_DATA_OFFSET member to allow adding that compatibly. An
implementation of the caching scheme for GTK+ can be found at . The
cache generator which is included in the patch depends only on glib, and
it may be a good idea to move it to freedesktop.org as well.
Regards, Matthias Clasen
The cache file format:
2 CARD16 MAJOR_VERSION 1
2 CARD16 MINOR_VERSION 0
4 CARD32 HASH_OFFSET
4 CARD32 DIRECTORY_LIST_OFFSET
4 CARD32 N_DIRECTORIES
4*N_DIRECTORIES CARD32 DIRECTORY_OFFSET
4 CARD32 N_BUCKETS
4*N_BUCKETS CARD32 ICON_OFFSET
4 CARD32 CHAIN_OFFSET
4 CARD32 NAME_OFFSET
4 CARD32 IMAGE_LIST_OFFSET
4 CARD32 N_IMAGES
4*N_IMAGES Image IMAGES
2 CARD16 DIRECTORY_INDEX
2 ICON_FLAGS FLAGS
4 CARD32 IMAGE_DATA_OFFSET
* All offsets are from in bytes from the beginning of the file
* Strings are zero-terminated
* All numbers are in network (big-endian) order. This is
necessary because the data will be stored in arch-independent
directories like /usr/share/icons or even in user's
* The hash function is that used by g_str_hash()
icon_str_hash (gconstpointer key)
const char *p = key;
unsigned int h = *p;
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
This should not be implemented by calling g_str_hash(). For
optimal results, N_BUCKETS should be typically be prime.
* The same file format is used for icon themes (e.g.,
/usr/share/icons/Bluecurve) and for unthemed icon directories
For an unthemed directory, N_DIRECTORIES==0 and each
image has a DIRECTORY_INDEX field of 0xFFFF.
* Up-to-dateness of a cache file is determined simply:
If the mod-time on the directory where the cache file
lives is newer than the mod-time of the cache file,
the cache file is out of date.
* Cache files have to be written atomically - write to a
temporary name, then move over the old file - so that
clients that have the old cache file open and mmap'ed
won't get corrupt data.
More information about the xdg