* include/freetype/cache/ftccache.h, src/cache/ftccache.i, src/cache/ftccache.c: cleaning up the cache sub-system code, linear hashing is now the default
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
diff --git a/ChangeLog b/ChangeLog
index 57c05ed..aa61bd4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-07-17 David Turner <david@freetype.org>
+
+ * include/freetype/cache/ftccache.h, src/cache/ftccache.i,
+ src/cache/ftccache.c: cleaning up the cache sub-system code, linear
+ hashing is now the default
+
2002-07-11 David Turner <david@freetype.org>
* src/sfnt/ttload.c, src/sfnt/ttload.h, src/sfnt/ttdriver.c: changing
diff --git a/include/freetype/cache/ftccache.h b/include/freetype/cache/ftccache.h
index 1871a0f..701b13e 100644
--- a/include/freetype/cache/ftccache.h
+++ b/include/freetype/cache/ftccache.h
@@ -23,9 +23,6 @@
/* define to allow cache lookup inlining */
#define FTC_CACHE_USE_INLINE
-/* define to use linear hash table */
-#define FTC_CACHE_USE_LINEAR_HASHING
-
FT_BEGIN_HEADER
@@ -181,14 +178,9 @@ FT_BEGIN_HEADER
FT_UInt cache_index; /* in manager's table */
FT_Pointer cache_data; /* used by cache node methods */
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
FT_UFast p;
FT_UFast mask;
FT_Long slack;
-#else
- FT_UFast nodes;
- FT_UFast size;
-#endif
FTC_Node* buckets;
FT_LruList_ClassRec family_class;
diff --git a/src/cache/ftccache.c b/src/cache/ftccache.c
index 00ec2ac..b54065b 100644
--- a/src/cache/ftccache.c
+++ b/src/cache/ftccache.c
@@ -24,8 +24,6 @@
#include "ftcerror.h"
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
-
#define FTC_HASH_MAX_LOAD 2
#define FTC_HASH_MIN_LOAD 1
#define FTC_HASH_SUB_LOAD ( FTC_HASH_MAX_LOAD - FTC_HASH_MIN_LOAD )
@@ -33,7 +31,6 @@
/* this one _must_ be a power of 2! */
#define FTC_HASH_INITIAL_SIZE 8
-#endif /* FTC_CACHE_USE_LINEAR_HASHING */
/*************************************************************************/
/*************************************************************************/
@@ -155,8 +152,6 @@
}
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
-
/* remove a node from its cache's hash table */
static FT_Error
ftc_node_hash_unlink( FTC_Node node,
@@ -166,7 +161,7 @@
FTC_Node *pnode;
FT_UInt index, num_buckets;
-
+
index = (FT_UInt)( node->hash & cache->mask );
if ( index < cache->p )
index = (FT_UInt)( node->hash & ( 2 * cache->mask + 1 ) );
@@ -236,41 +231,7 @@
return error;
}
-#else /* !FTC_CACHE_USE_LINEAR_HASHING */
-
- /* remove a node from its cache's hash table */
- static void
- ftc_node_hash_unlink( FTC_Node node,
- FTC_Cache cache )
- {
- FTC_Node *pnode = cache->buckets + ( node->hash % cache->size );
-
-
- for (;;)
- {
- if ( *pnode == NULL )
- {
- FT_ERROR(( "FreeType.cache.hash_unlink: unknown node!\n" ));
- return;
- }
-
- if ( *pnode == node )
- {
- *pnode = node->link;
- node->link = NULL;
-
- cache->nodes--;
- return;
- }
-
- pnode = &(*pnode)->link;
- }
- }
-#endif /* !FTC_CACHE_USE_LINEAR_HASHING */
-
-
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
/* add a node to the "top" of its cache's hash table */
static FT_Error
@@ -345,23 +306,6 @@
return error;
}
-#else /* !FTC_CACHE_USE_LINEAR_HASHING */
-
- /* add a node to the "top" of its cache's hash table */
- static void
- ftc_node_hash_link( FTC_Node node,
- FTC_Cache cache )
- {
- FTC_Node *pnode = cache->buckets + ( node->hash % cache->size );
-
-
- node->link = *pnode;
- *pnode = node;
-
- cache->nodes++;
- }
-
-#endif /* !FTC_CACHE_USE_LINEAR_HASHING */
@@ -476,125 +420,6 @@
/*************************************************************************/
/*************************************************************************/
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
-
- /* nothing */
-
-#else /* !FTC_CACHE_USE_LINEAR_HASHING */
-
-#define FTC_PRIMES_MIN 7
-#define FTC_PRIMES_MAX 13845163
-
- static const FT_UInt ftc_primes[] =
- {
- 7,
- 11,
- 19,
- 37,
- 73,
- 109,
- 163,
- 251,
- 367,
- 557,
- 823,
- 1237,
- 1861,
- 2777,
- 4177,
- 6247,
- 9371,
- 14057,
- 21089,
- 31627,
- 47431,
- 71143,
- 106721,
- 160073,
- 240101,
- 360163,
- 540217,
- 810343,
- 1215497,
- 1823231,
- 2734867,
- 4102283,
- 6153409,
- 9230113,
- 13845163,
- };
-
-
- static FT_UFast
- ftc_prime_closest( FT_UFast num )
- {
- FT_UInt i;
-
-
- for ( i = 0; i < sizeof ( ftc_primes ) / sizeof ( ftc_primes[0] ); i++ )
- if ( ftc_primes[i] > num )
- return ftc_primes[i];
-
- return FTC_PRIMES_MAX;
- }
-
-
-#define FTC_CACHE_RESIZE_TEST( c ) \
- ( (c)->nodes*3 < (c)->size || \
- (c)->size*3 < (c)->nodes )
-
-
- static void
- ftc_cache_resize( FTC_Cache cache )
- {
- FT_UFast new_size;
-
-
- new_size = ftc_prime_closest( cache->nodes );
- if ( new_size != cache->size )
- {
- FT_Memory memory = cache->memory;
- FT_Error error;
- FTC_Node* new_buckets ;
- FT_ULong i;
-
-
- /* no need to report an error; we'll simply keep using the same */
- /* buckets number / size */
- if ( FT_NEW_ARRAY( new_buckets, new_size ) )
- return;
-
- for ( i = 0; i < cache->size; i++ )
- {
- FTC_Node node, next, *pnode;
- FT_UFast hash;
-
-
- node = cache->buckets[i];
- while ( node )
- {
- next = node->link;
- hash = node->hash % new_size;
- pnode = new_buckets + hash;
-
- node->link = pnode[0];
- pnode[0] = node;
-
- node = next;
- }
- }
-
- if ( cache->buckets )
- FT_FREE( cache->buckets );
-
- cache->buckets = new_buckets;
- cache->size = new_size;
-
- FT_UNUSED( error );
- }
- }
-
-#endif /* !FTC_CACHE_USE_LINEAR_HASHING */
FT_EXPORT_DEF( FT_Error )
@@ -605,8 +430,6 @@
FT_Error error;
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
-
cache->p = 0;
cache->mask = FTC_HASH_INITIAL_SIZE - 1;
cache->slack = FTC_HASH_INITIAL_SIZE * FTC_HASH_MAX_LOAD;
@@ -614,16 +437,6 @@
if ( FT_NEW_ARRAY( cache->buckets, FTC_HASH_INITIAL_SIZE * 2 ) )
goto Exit;
-#else /* !FTC_CACHE_USE_LINEAR_HASHING */
-
- cache->nodes = 0;
- cache->size = FTC_PRIMES_MIN;
-
- if ( FT_NEW_ARRAY( cache->buckets, cache->size ) )
- goto Exit;
-
-#endif /* !FTC_CACHE_USE_LINEAR_HASHING */
-
/* now, initialize the lru list of families for this cache */
if ( clazz->family_size > 0 )
{
@@ -665,11 +478,7 @@
FT_UFast i;
FT_UInt count;
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
count = cache->p + cache->mask + 1;
-#else
- count = cache->size;
-#endif
for ( i = 0; i < count; i++ )
{
@@ -696,11 +505,8 @@
cache->buckets[i] = NULL;
}
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
cache->p = 0;
-#else
- cache->nodes = 0;
-#endif
+
/* destroy the families */
if ( cache->families )
FT_LruList_Reset( cache->families );
@@ -719,12 +525,8 @@
ftc_cache_clear( cache );
FT_FREE( cache->buckets );
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
cache->mask = 0;
cache->slack = 0;
-#else
- cache->size = 0;
-#endif
if ( cache->families )
{
@@ -755,8 +557,6 @@
query->hash = 0;
query->family = NULL;
-#if 1
-
/* XXX: we break encapsulation for the sake of speed! */
{
/* first of all, find the relevant family */
@@ -799,20 +599,11 @@
;
}
-#else
-
- error = FT_LruList_Lookup( cache->families, query, &lru );
- if ( !error )
-
-#endif
{
FTC_Family family = (FTC_Family) lru;
FT_UFast hash = query->hash;
FTC_Node* bucket;
-
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
-
- FT_UInt index;
+ FT_UInt index;
index = hash & cache->mask;
@@ -821,12 +612,6 @@
bucket = cache->buckets + index;
-#else
-
- bucket = cache->buckets + (hash % cache->size);
-
-#endif
-
if ( query->family != family ||
family->fam_index >= cache->manager->families.size )
@@ -897,7 +682,6 @@
goto Exit;
}
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
error = ftc_node_hash_link( node, cache );
if ( error )
{
@@ -905,9 +689,6 @@
FT_FREE( node );
goto Exit;
}
-#else
- ftc_node_hash_link( node, cache );
-#endif
ftc_node_mru_link( node, cache->manager );
@@ -921,12 +702,6 @@
node->ref_count--;
}
-#ifndef FTC_CACHE_USE_LINEAR_HASHING
- /* try to resize the hash table if appropriate */
- if ( FTC_CACHE_RESIZE_TEST( cache ) )
- ftc_cache_resize( cache );
-#endif
-
*anode = node;
}
}
diff --git a/src/cache/ftccache.i b/src/cache/ftccache.i
index 4cd38db..49faa93 100644
--- a/src/cache/ftccache.i
+++ b/src/cache/ftccache.i
@@ -78,7 +78,6 @@
family = (FTC_Family)lru;
hash = query->hash;
-#ifdef FTC_CACHE_USE_LINEAR_HASHING
{
FT_UInt index;
@@ -89,9 +88,6 @@
bucket = cache->buckets + index;
}
-#else
- bucket = cache->buckets + ( hash % cache->size );
-#endif
#ifdef FT_DEBUG_LEVEL_ERROR
if ( query->family != family ||