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.c78
1 files changed, 37 insertions, 41 deletions
diff --git a/src/3rdparty/freetype/src/cache/ftcmanag.c b/src/3rdparty/freetype/src/cache/ftcmanag.c
index bd585968e3..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-2019 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,
@@ -16,12 +16,11 @@
*/
-#include <ft2build.h>
-#include FT_CACHE_H
+#include <freetype/ftcache.h>
#include "ftcmanag.h"
-#include FT_INTERNAL_OBJECTS_H
-#include FT_INTERNAL_DEBUG_H
-#include FT_SIZES_H
+#include <freetype/internal/ftobjs.h>
+#include <freetype/internal/ftdebug.h>
+#include <freetype/ftsizes.h>
#include "ftccback.h"
#include "ftcerror.h"
@@ -358,7 +357,7 @@
{
FT_Error error;
FT_Memory memory;
- FTC_Manager manager = 0;
+ FTC_Manager manager = NULL;
if ( !library )
@@ -369,7 +368,7 @@
memory = library->memory;
- if ( FT_NEW( manager ) )
+ if ( FT_QNEW( manager ) )
goto Exit;
if ( max_faces == 0 )
@@ -384,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;
@@ -400,6 +400,10 @@
manager,
memory );
+ manager->nodes_list = NULL;
+ manager->num_nodes = 0;
+ manager->num_caches = 0;
+
*amanager = manager;
Exit:
@@ -422,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];
@@ -485,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 );
@@ -516,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 ));
}
}
@@ -533,7 +537,7 @@
FT_LOCAL_DEF( void )
FTC_Manager_Compress( FTC_Manager manager )
{
- FTC_Node node, first;
+ FTC_Node node, prev, first;
if ( !manager )
@@ -544,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
@@ -553,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 );
}
@@ -594,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;
@@ -629,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 )
@@ -650,13 +650,9 @@
ftc_node_destroy( node, manager );
result++;
}
+ } while ( node != first && result < count );
- if ( node == first )
- break;
-
- node = prev;
- }
- return result;
+ return result;
}
@@ -690,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--;
}