commit last fixes and optimisations to the cache manager. The performance of cache hits has increased between 20 and 50% !!
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
diff --git a/include/freetype/cache/ftccache.h b/include/freetype/cache/ftccache.h
index 0a0e6ec..d45b223 100644
--- a/include/freetype/cache/ftccache.h
+++ b/include/freetype/cache/ftccache.h
@@ -21,7 +21,7 @@
/* define to allow cache lookup inlining */
-#undef FTC_CACHE_USE_INLINE
+#define FTC_CACHE_USE_INLINE
/* define to use linear hash table */
#define FTC_CACHE_USE_LINEAR_HASHING
diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index 41d2855..9fd37ee 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -257,8 +257,8 @@ FT_BEGIN_HEADER
/* */
/* Don't define any of these macros to compile in `release' mode! */
/* */
-#define FT_DEBUG_LEVEL_ERROR
-#define FT_DEBUG_LEVEL_TRACE
+#undef FT_DEBUG_LEVEL_ERROR
+#undef FT_DEBUG_LEVEL_TRACE
/*************************************************************************/
@@ -273,7 +273,7 @@ FT_BEGIN_HEADER
/* Note that the memory debugger is only activated at runtime when */
/* when the _environment_ variable "FT_DEBUG_MEMORY" is also defined! */
/* */
-#define FT_DEBUG_MEMORY
+#undef FT_DEBUG_MEMORY
/*************************************************************************/
diff --git a/src/cache/ftccache.c b/src/cache/ftccache.c
index 51522d5..d5bcf92 100644
--- a/src/cache/ftccache.c
+++ b/src/cache/ftccache.c
@@ -23,10 +23,6 @@
#include "ftcerror.h"
-/* define for level-1 optimisations */
-#undef OPT1
-
-
#ifdef FTC_CACHE_USE_LINEAR_HASHING
@@ -75,7 +71,9 @@
if ( first )
{
FTC_Node last = first->mru_prev;
-
+
+ FT_ASSERT( last->mru_next == first );
+
node->mru_prev = last;
node->mru_next = first;
@@ -137,11 +135,12 @@
{
FTC_Node prev = node->mru_prev;
FTC_Node next = node->mru_next;
- FTC_Node last = first->mru_prev;
+ FTC_Node last;
prev->mru_next = next;
next->mru_prev = prev;
+ last = first->mru_prev;
node->mru_next = first;
node->mru_prev = last;
first->mru_prev = node;
@@ -741,7 +740,8 @@
query->hash = 0;
query->family = NULL;
-#ifdef OPT1
+ /* XXX: we break encapsulation for the sake of speed !! */
+#if 1
{
/* first of all, find the relevant family */
FT_LruList list = cache->families;
@@ -827,14 +827,9 @@
if ( node == NULL )
break;
-#ifdef OPT1
if ( node->hash == hash &&
(FT_UInt)node->fam_index == family->fam_index &&
compare( node, query, cache ) )
-#else
- if ( (FT_UInt)node->fam_index == family->fam_index &&
- compare( node, query, cache ) )
-#endif
{
/* move to head of bucket list */
if ( pnode != bucket )
diff --git a/src/cache/ftccmap.c b/src/cache/ftccmap.c
index f4ec779..8eb9a84 100644
--- a/src/cache/ftccmap.c
+++ b/src/cache/ftccmap.c
@@ -318,6 +318,23 @@
}
+#ifdef FTC_CACHE_USE_INLINE
+
+# define GEN_CACHE_FAMILY_COMPARE(f,q,c) \
+ ftc_cmap_family_compare( (FTC_CMapFamily)(f), (FTC_CMapQuery)(q) )
+
+# define GEN_CACHE_NODE_COMPARE(n,q,c) \
+ ftc_cmap_node_compare( (FTC_CMapNode)(n), (FTC_CMapQuery)(q) )
+
+# define GEN_CACHE_LOOKUP ftc_cmap_cache_lookup
+# include "ftccache.i"
+
+#else /* !FTC_CACHE_USE_INLINE */
+
+# define ftc_cmap_cache_lookup ftc_cache_lookup
+
+#endif /* !FTC_CACHE_USE_INLINE */
+
/* documentation is in ftccmap.h */
FT_EXPORT_DEF( FT_UInt )
@@ -340,9 +357,9 @@
cquery.desc = desc;
cquery.char_code = char_code;
- error = ftc_cache_lookup( FTC_CACHE( cache ),
- FTC_QUERY( &cquery ),
- (FTC_Node*)&node );
+ error = ftc_cmap_cache_lookup( FTC_CACHE( cache ),
+ FTC_QUERY( &cquery ),
+ (FTC_Node*)&node );
if ( !error )
{
FT_UInt offset = (FT_UInt)( char_code - node->first );