misc/libfreetype/src/cache/ftccache.c
author nemo
Sun, 11 Sep 2011 10:46:53 -0400
changeset 5856 ed97138dc414
parent 5172 88f2e05288ba
permissions -rw-r--r--
Should prevent a crasher when drowning while firing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftccache.c                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    The FreeType internal cache interface (body).                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010,   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*            2011 by                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include "ftcmanag.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include "ftccback.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include "ftcerror.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#define FT_COMPONENT  trace_cache
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
#define FTC_HASH_MAX_LOAD  2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
#define FTC_HASH_MIN_LOAD  1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#define FTC_HASH_SUB_LOAD  ( FTC_HASH_MAX_LOAD - FTC_HASH_MIN_LOAD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /* this one _must_ be a power of 2! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#define FTC_HASH_INITIAL_SIZE  8
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /*****                   CACHE NODE DEFINITIONS                      *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /* add a new node to the head of the manager's circular MRU list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  ftc_node_mru_link( FTC_Node     node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
                     FTC_Manager  manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
    void  *nl = &manager->nodes_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    FTC_MruNode_Prepend( (FTC_MruNode*)nl,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
                         (FTC_MruNode)node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    manager->num_nodes++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  /* remove a node from the manager's MRU list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  ftc_node_mru_unlink( FTC_Node     node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
                       FTC_Manager  manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    void  *nl = &manager->nodes_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    FTC_MruNode_Remove( (FTC_MruNode*)nl,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
                        (FTC_MruNode)node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    manager->num_nodes--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
#ifndef FTC_INLINE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  /* move a node to the head of the manager's MRU list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  ftc_node_mru_up( FTC_Node     node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
                   FTC_Manager  manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    FTC_MruNode_Up( (FTC_MruNode*)&manager->nodes_list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
                    (FTC_MruNode)node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  /* get a top bucket for specified hash from cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
   * body for FTC_NODE__TOP_FOR_HASH( cache, hash )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  FT_LOCAL_DEF( FTC_Node* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  ftc_get_top_node_for_hash( FTC_Cache   cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
                             FT_PtrDist  hash )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    FTC_Node*  pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    FT_UInt    idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    idx = (FT_UInt)( hash & cache->mask );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    if ( idx < cache->p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
      idx = (FT_UInt)( hash & ( 2 * cache->mask + 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    pnode = cache->buckets + idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    return pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
#endif /* !FTC_INLINE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
  /* Note that this function cannot fail.  If we cannot re-size the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
   * buckets array appropriately, we simply degrade the hash table's
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
   * performance!
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
  ftc_cache_resize( FTC_Cache  cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
      FTC_Node  node, *pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
      FT_UFast  p     = cache->p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
      FT_UFast  mask  = cache->mask;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      FT_UFast  count = mask + p + 1;    /* number of buckets */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
      /* do we need to shrink the buckets array? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      if ( cache->slack < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
        FTC_Node  new_list = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
        /* try to expand the buckets array _before_ splitting
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
         * the bucket lists
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
        if ( p >= mask )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
          FT_Memory  memory = cache->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
          FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
          /* if we can't expand the array, leave immediately */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
          if ( FT_RENEW_ARRAY( cache->buckets,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
                               ( mask + 1 ) * 2, ( mask + 1 ) * 4 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
        /* split a single bucket */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
        pnode = cache->buckets + p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
        for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
          node = *pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
          if ( node == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
          if ( node->hash & ( mask + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
            *pnode     = node->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
            node->link = new_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
            new_list   = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
            pnode = &node->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
        cache->buckets[p + mask + 1] = new_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
        cache->slack += FTC_HASH_MAX_LOAD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
        if ( p >= mask )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
          cache->mask = 2 * mask + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
          cache->p    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
          cache->p = p + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      /* do we need to expand the buckets array? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
      else if ( cache->slack > (FT_Long)count * FTC_HASH_SUB_LOAD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
        FT_UFast   old_index = p + mask;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
        FTC_Node*  pold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
        if ( old_index + 1 <= FTC_HASH_INITIAL_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
        if ( p == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
          FT_Memory  memory = cache->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
          FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
          /* if we can't shrink the array, leave immediately */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
          if ( FT_RENEW_ARRAY( cache->buckets,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
                               ( mask + 1 ) * 2, mask + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
          cache->mask >>= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
          p             = cache->mask;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
          p--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
        pnode = cache->buckets + p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
        while ( *pnode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
          pnode = &(*pnode)->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
        pold   = cache->buckets + old_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
        *pnode = *pold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
        *pold  = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
        cache->slack -= FTC_HASH_MAX_LOAD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
        cache->p      = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
      /* otherwise, the hash table is balanced */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
  /* remove a node from its cache's hash table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
  ftc_node_hash_unlink( FTC_Node   node0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
                        FTC_Cache  cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    FTC_Node  *pnode = FTC_NODE__TOP_FOR_HASH( cache, node0->hash );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      FTC_Node  node = *pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
      if ( node == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        FT_TRACE0(( "ftc_node_hash_unlink: unknown node\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
      if ( node == node0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
      pnode = &(*pnode)->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    *pnode      = node0->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    node0->link = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    cache->slack++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    ftc_cache_resize( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
  /* add a node to the `top' of its cache's hash table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
  ftc_node_hash_link( FTC_Node   node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
                      FTC_Cache  cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
    FTC_Node  *pnode = FTC_NODE__TOP_FOR_HASH( cache, node->hash );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    node->link = *pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    *pnode     = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    cache->slack--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    ftc_cache_resize( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
  /* remove a node from the cache manager */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
  ftc_node_destroy( FTC_Node     node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
                    FTC_Manager  manager )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    FTC_Cache  cache;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
#ifdef FT_DEBUG_ERROR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
    /* find node's cache */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    if ( node->cache_index >= manager->num_caches )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
      FT_TRACE0(( "ftc_node_destroy: invalid node handle\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
    cache = manager->caches[node->cache_index];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
#ifdef FT_DEBUG_ERROR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
    if ( cache == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
      FT_TRACE0(( "ftc_node_destroy: invalid node handle\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
    manager->cur_weight -= cache->clazz.node_weight( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
    /* remove node from mru list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
    ftc_node_mru_unlink( node, manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
    /* remove node from cache's hash table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
    ftc_node_hash_unlink( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
    /* now finalize it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    cache->clazz.node_free( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    /* check, just in case of general corruption :-) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    if ( manager->num_nodes == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
      FT_TRACE0(( "ftc_node_destroy: invalid cache node count (%d)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
                  manager->num_nodes ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
  /*****                    ABSTRACT CACHE CLASS                       *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
  FTC_Cache_Init( FTC_Cache  cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
    return ftc_cache_init( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
  ftc_cache_init( FTC_Cache  cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    FT_Memory  memory = cache->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
    cache->p     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    cache->mask  = FTC_HASH_INITIAL_SIZE - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    cache->slack = FTC_HASH_INITIAL_SIZE * FTC_HASH_MAX_LOAD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    (void)FT_NEW_ARRAY( cache->buckets, FTC_HASH_INITIAL_SIZE * 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
  FTC_Cache_Clear( FTC_Cache  cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
    if ( cache && cache->buckets )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
      FTC_Manager  manager = cache->manager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
      FT_UFast     i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
      FT_UFast     count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
      count = cache->p + cache->mask + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      for ( i = 0; i < count; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
        FTC_Node  *pnode = cache->buckets + i, next, node = *pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
        while ( node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
          next        = node->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
          node->link  = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
          /* remove node from mru list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
          ftc_node_mru_unlink( node, manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
          /* now finalize it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
          manager->cur_weight -= cache->clazz.node_weight( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
          cache->clazz.node_free( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
          node = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
        cache->buckets[i] = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
      ftc_cache_resize( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
  ftc_cache_done( FTC_Cache  cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    if ( cache->memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
      FT_Memory  memory = cache->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
      FTC_Cache_Clear( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
      FT_FREE( cache->buckets );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
      cache->mask  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
      cache->p     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
      cache->slack = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
      cache->memory = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  FTC_Cache_Done( FTC_Cache  cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
    ftc_cache_done( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
  ftc_cache_add( FTC_Cache  cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
                 FT_PtrDist hash,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
                 FTC_Node   node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
    node->hash        = hash;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
    node->cache_index = (FT_UInt16)cache->index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
    node->ref_count   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
    ftc_node_hash_link( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
    ftc_node_mru_link( node, cache->manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      FTC_Manager  manager = cache->manager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
      manager->cur_weight += cache->clazz.node_weight( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
      if ( manager->cur_weight >= manager->max_weight )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
        node->ref_count++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
        FTC_Manager_Compress( manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
        node->ref_count--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
  FTC_Cache_NewNode( FTC_Cache   cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
                     FT_PtrDist  hash,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
                     FT_Pointer  query,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
                     FTC_Node   *anode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
    FTC_Node  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
     * We use the FTC_CACHE_TRYLOOP macros to support out-of-memory
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
     * errors (OOM) correctly, i.e., by flushing the cache progressively
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
     * in order to make more room.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
    FTC_CACHE_TRYLOOP( cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
      error = cache->clazz.node_new( &node, query, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    FTC_CACHE_TRYLOOP_END( NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
      node = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
     /* don't assume that the cache has the same number of buckets, since
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
      * our allocation request might have triggered global cache flushing
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
      ftc_cache_add( cache, hash, node );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
    *anode = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
#ifndef FTC_INLINE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
  FTC_Cache_Lookup( FTC_Cache   cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
                    FT_PtrDist  hash,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
                    FT_Pointer  query,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
                    FTC_Node   *anode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    FTC_Node*  bucket;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
    FTC_Node*  pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
    FTC_Node   node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
    FT_Error   error        = FTC_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
    FT_Bool    list_changed = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    FTC_Node_CompareFunc  compare = cache->clazz.node_compare;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    if ( cache == NULL || anode == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
      return FTC_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    /* Go to the `top' node of the list sharing same masked hash */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    bucket = pnode = FTC_NODE__TOP_FOR_HASH( cache, hash );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
    /* Lookup a node with exactly same hash and queried properties.  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
    /* NOTE: _nodcomp() may change the linked list to reduce memory. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
      node = *pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
      if ( node == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
        goto NewNode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      if ( node->hash == hash                           &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
           compare( node, query, cache, &list_changed ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
      pnode = &node->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
    if ( list_changed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
      /* Update bucket by modified linked list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
      bucket = pnode = FTC_NODE__TOP_FOR_HASH( cache, hash );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
      /* Update pnode by modified linked list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
      while ( *pnode != node )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
        if ( *pnode == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
          FT_ERROR(( "FTC_Cache_Lookup: oops!!!  node missing\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
          goto NewNode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
          pnode = &((*pnode)->link);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
    /* Reorder the list to move the found node to the `top' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    if ( node != *bucket )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
      *pnode     = node->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
      node->link = *bucket;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
      *bucket    = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
    /* move to head of MRU list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
      FTC_Manager  manager = cache->manager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
      if ( node != manager->nodes_list )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
        ftc_node_mru_up( node, manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
    *anode = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
  NewNode:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
    return FTC_Cache_NewNode( cache, hash, query, anode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
#endif /* !FTC_INLINE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
  FTC_Cache_RemoveFaceID( FTC_Cache   cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
                          FTC_FaceID  face_id )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
    FT_UFast     i, count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
    FTC_Manager  manager = cache->manager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
    FTC_Node     frees   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
    count = cache->p + cache->mask + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
    for ( i = 0; i < count; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
      FTC_Node*  bucket = cache->buckets + i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
      FTC_Node*  pnode  = bucket;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
      for ( ;; )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
        FTC_Node  node = *pnode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
        FT_Bool   list_changed = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
        if ( node == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
        if ( cache->clazz.node_remove_faceid( node, face_id,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
                                              cache, &list_changed ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
          *pnode     = node->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
          node->link = frees;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
          frees      = node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
          pnode = &node->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
    /* remove all nodes in the free list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
    while ( frees )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
      FTC_Node  node;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
      node  = frees;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
      frees = node->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
      manager->cur_weight -= cache->clazz.node_weight( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
      ftc_node_mru_unlink( node, manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
      cache->clazz.node_free( node, cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      cache->slack++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
    ftc_cache_resize( cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
/* END */