Icon theme index files



I happened to notice the other day that when you start up GTK+ with
the Red Hat Bluecurve icon theme, out of the total of 1M of allocated
memory, about 0.5M is simply icon theme.

Also, as noted earlier, we are doing lots of system call traffic
on startup to read all this data in.

Here's a proposal to fix these problems: for each icon theme directory
we keep a binary icon index file which we can simply mmap() and
use directly.

The directory index 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 

 $HOME/.local/share/icons/Bluecurve/index.theme

That overrides

 /usr/share/icons/Bluecurve/index.theme

and chances how lookup happens for icons in /usr/share/icons/Bluecurve.

Rather it just holds all stuff we get currently by trolling the 
filesystem. Attached is a first-draft proposal for the file format.

Regards,
						Owen


Header:
2		CARD16		MAJOR_VERSION
2		CARD16		MINOR_VERSION
4		CARD32		HASH_OFFSET
4		CARD32		DIRECTORY_LIST_OFFSET

DirectoryList:
4 		CARD32		N_DIRECTORIES
4*N_DIRECTORIES	CARD32		DIRECTORY_OFFSET

Directory:
4 		CARD32		NAME_OFFSET

Hash:
4		CARD32		N_BUCKETS
4*N_BUCKETS	CARD32		ICON_OFFSET

Icon:
4		CARD32		CHAIN_OFFSET
4		CARD32		NAME_OFFSET
4		CARD32		IMAGE_LIST_OFFSET

ImageList:
4		CARD32		N_IMAGES
4*N_IMAGES	Image		IMAGES

ICON_FLAGS
HAS_SUFFIX_PNG	1
HAS_SUFFIX_XPM	2
HAS_SUFFIX_SVG	4
HAS_ICON_FILE	8

Image:
2		CARD16			DIRECTORY_INDEX
2		ICON_FLAGS		FLAGS

Notes:

* 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 
  home directories.

* The hash function is that used by g_str_hash()

  unsigned int
  icon_str_hash (gconstpointer key)
  {
    const char *p = key;
    unsigned int h = *p;

    if (h)
      for (p += 1; *p != '\0'; p++)
        h = (h << 5) - h + *p;

    return h;
  }

 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
  (e.g., /usr/share/pixmaps)

  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.

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]