summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/cache/ftcmanag.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/cache/ftcmanag.c')
-rw-r--r--src/3rdparty/freetype/src/cache/ftcmanag.c69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/3rdparty/freetype/src/cache/ftcmanag.c b/src/3rdparty/freetype/src/cache/ftcmanag.c
index 436d41f374..94f8469c92 100644
--- a/src/3rdparty/freetype/src/cache/ftcmanag.c
+++ b/src/3rdparty/freetype/src/cache/ftcmanag.c
@@ -4,7 +4,7 @@
*
* FreeType Cache Manager (body).
*
- * Copyright (C) 2000-2020 by
+ * Copyright (C) 2000-2023 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used,
@@ -357,7 +357,7 @@
{
FT_Error error;
FT_Memory memory;
- FTC_Manager manager = 0;
+ FTC_Manager manager = NULL;
if ( !library )
@@ -368,7 +368,7 @@
memory = library->memory;
- if ( FT_NEW( manager ) )
+ if ( FT_QNEW( manager ) )
goto Exit;
if ( max_faces == 0 )
@@ -383,6 +383,7 @@
manager->library = library;
manager->memory = memory;
manager->max_weight = max_bytes;
+ manager->cur_weight = 0;
manager->request_face = requester;
manager->request_data = req_data;
@@ -399,6 +400,10 @@
manager,
memory );
+ manager->nodes_list = NULL;
+ manager->num_nodes = 0;
+ manager->num_caches = 0;
+
*amanager = manager;
Exit:
@@ -421,7 +426,7 @@
memory = manager->memory;
/* now discard all caches */
- for (idx = manager->num_caches; idx-- > 0; )
+ for ( idx = manager->num_caches; idx-- > 0; )
{
FTC_Cache cache = manager->caches[idx];
@@ -484,8 +489,8 @@
FTC_Cache cache = manager->caches[node->cache_index];
- if ( (FT_UInt)node->cache_index >= manager->num_caches )
- FT_TRACE0(( "FTC_Manager_Check: invalid node (cache index = %ld\n",
+ if ( node->cache_index >= manager->num_caches )
+ FT_TRACE0(( "FTC_Manager_Check: invalid node (cache index = %hu\n",
node->cache_index ));
else
weight += cache->clazz.node_weight( node, cache );
@@ -515,7 +520,7 @@
if ( count != manager->num_nodes )
FT_TRACE0(( "FTC_Manager_Check:"
- " invalid cache node count %d instead of %d\n",
+ " invalid cache node count %u instead of %u\n",
manager->num_nodes, count ));
}
}
@@ -532,7 +537,7 @@
FT_LOCAL_DEF( void )
FTC_Manager_Compress( FTC_Manager manager )
{
- FTC_Node node, first;
+ FTC_Node node, prev, first;
if ( !manager )
@@ -543,7 +548,7 @@
#ifdef FT_DEBUG_ERROR
FTC_Manager_Check( manager );
- FT_TRACE0(( "compressing, weight = %ld, max = %ld, nodes = %d\n",
+ FT_TRACE0(( "compressing, weight = %ld, max = %ld, nodes = %u\n",
manager->cur_weight, manager->max_weight,
manager->num_nodes ));
#endif
@@ -552,20 +557,16 @@
return;
/* go to last node -- it's a circular list */
- node = FTC_NODE_PREV( first );
+ prev = FTC_NODE_PREV( first );
do
{
- FTC_Node prev;
-
-
- prev = ( node == first ) ? NULL : FTC_NODE_PREV( node );
+ node = prev;
+ prev = FTC_NODE_PREV( node );
if ( node->ref_count <= 0 )
ftc_node_destroy( node, manager );
- node = prev;
-
- } while ( node && manager->cur_weight > manager->max_weight );
+ } while ( node != first && manager->cur_weight > manager->max_weight );
}
@@ -593,7 +594,7 @@
goto Exit;
}
- if ( !FT_ALLOC( cache, clazz->cache_size ) )
+ if ( !FT_QALLOC( cache, clazz->cache_size ) )
{
cache->manager = manager;
cache->memory = memory;
@@ -628,20 +629,20 @@
FT_UInt count )
{
FTC_Node first = manager->nodes_list;
- FTC_Node node;
- FT_UInt result;
+ FTC_Node prev, node;
+ FT_UInt result = 0;
/* try to remove `count' nodes from the list */
- if ( !first ) /* empty list! */
- return 0;
+ if ( !first || !count )
+ return result;
- /* go to last node - it's a circular list */
- node = FTC_NODE_PREV(first);
- for ( result = 0; result < count; )
+ /* go to last node -- it's a circular list */
+ prev = FTC_NODE_PREV( first );
+ do
{
- FTC_Node prev = FTC_NODE_PREV( node );
-
+ node = prev;
+ prev = FTC_NODE_PREV( node );
/* don't touch locked nodes */
if ( node->ref_count <= 0 )
@@ -649,13 +650,9 @@
ftc_node_destroy( node, manager );
result++;
}
+ } while ( node != first && result < count );
- if ( node == first )
- break;
-
- node = prev;
- }
- return result;
+ return result;
}
@@ -689,9 +686,9 @@
FTC_Node_Unref( FTC_Node node,
FTC_Manager manager )
{
- if ( node &&
- manager &&
- (FT_UInt)node->cache_index < manager->num_caches )
+ if ( node &&
+ manager &&
+ node->cache_index < manager->num_caches )
node->ref_count--;
}