1 /***************************************************************************/
5 /* FreeType template for generic cache. */
7 /* Copyright 2002 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
19 #ifndef GEN_CACHE_FAMILY_COMPARE
20 #error "GEN_CACHE_FAMILY_COMPARE not defined in template instantiation"
23 #ifndef GEN_CACHE_NODE_COMPARE
24 #error "GEN_CACHE_NODE_COMPARE not defined in template instantiation"
29 GEN_CACHE_LOOKUP( FTC_Cache cache,
41 /* XXX: we break encapsulation for the sake of speed! */
43 /* first of all, find the relevant family */
44 FT_LruList list = cache->families;
45 FT_LruNode fam, *pfam;
55 if ( GEN_CACHE_FAMILY_COMPARE( fam, query, list->data ) )
61 FT_ASSERT( fam != NULL );
63 /* move to top of list when needed */
64 if ( fam != list->nodes )
67 fam->next = list->nodes;
75 FTC_Node node, *pnode, *bucket;
78 family = (FTC_Family)lru;
85 idx = hash & cache->mask;
87 idx = hash & ( cache->mask * 2 + 1 );
89 bucket = cache->buckets + idx;
100 if ( node->hash == hash &&
101 (FT_UInt)node->fam_index == family->fam_index &&
102 GEN_CACHE_NODE_COMPARE( node, query, cache ) )
104 /* we place the following out of the loop to make it */
105 /* as small as possible... */
113 return ftc_cache_lookup( cache, query, anode );
116 /* move to head of bucket list */
117 if ( pnode != bucket )
120 node->link = *bucket;
124 /* move to head of MRU list */
125 if ( node != cache->manager->nodes_list )
127 /* XXX: again, this is an inlined version of ftc_node_mru_up */
128 FTC_Manager manager = cache->manager;
129 FTC_Node first = manager->nodes_list;
130 FTC_Node prev = node->mru_prev;
131 FTC_Node next = node->mru_next;
135 prev->mru_next = next;
136 next->mru_prev = prev;
138 last = first->mru_prev;
139 node->mru_next = first;
140 node->mru_prev = last;
141 first->mru_prev = node;
142 last->mru_next = node;
144 manager->nodes_list = node;
152 #undef GEN_CACHE_NODE_COMPARE
153 #undef GEN_CACHE_FAMILY_COMPARE
154 #undef GEN_CACHE_LOOKUP