* include/freetype/internal/ftmemory.h [FT_DEBUG_MEMORY]: Declare

FT_QAlloc_Debug and FT_QRealloc_Debug.

* src/base/ftutil.c (FT_QAlloc): Fix error and debug messages.
(FT_QRealloc): Call FT_QAlloc if original pointer is NULL.
Fix error message.
This commit is contained in:
Werner Lemberg 2004-06-24 06:56:06 +00:00
parent 4e56c0d8e3
commit 21ddf945c3
5 changed files with 85 additions and 45 deletions

View File

@ -1,25 +1,43 @@
2004-06-23 Werner Lemberg <wl@gnu.org>
* include/freetype/internal/ftmemory.h [FT_DEBUG_MEMORY]: Declare
FT_QAlloc_Debug and FT_QRealloc_Debug.
* src/base/ftutil.c (FT_QAlloc): Fix error and debug messages.
(FT_QRealloc): Call FT_QAlloc if original pointer is NULL.
Fix error message.
2004-06-23 David Turner <david@freetype.org> 2004-06-23 David Turner <david@freetype.org>
* include/freetype/internal/ftmemory.h, src/base/ftutil.c, * include/freetype/internal/ftmemory.h, src/base/ftutil.c
src/base/ftmemdbg.c: introducing the new FT_QAlloc and FT_QRealloc (FT_QAlloc, FT_QRealloc), src/base/ftdbgmem.c (FT_QAlloc_Debug,
functions that do perform allocation without zero-ing out the FT_QRealloc_Debug): New functions that perform allocation without
corresponding blocks. Corresponding macros like FT_QALLOC, FT_QNEW, zero-ing out the corresponding blocks.
etc.. have been defined too
* include/freetype/config/ftmodule.h: changed the order of modules * include/freetype/internal/ftmemory.h (FT_MEM_QALLOC,
in order to _dramatically_ improve the performance of face open/close FT_MEM_QREALLOC, FT_MEM_QNEW, FT_MEM_QNEW_ARRAY,
operations. For example, putting the TrueType driver first in the FT_MEM_QRENEW_ARRAY, FT_QALLOC, FT_QREALLOC, FT_QNEW, FT_QNEW_ARRAY,
list results in a 5X speedup when opening Vera.ttf !! FT_QRENEW_ARRAY): New macros.
The problem is really that the PCF and/or BDF drivers are broken * src/base/ftstream.c (FT_Stream_EnterFrame): Use FT_QALLOC.
and do a lot more than necessary simply to detect that they * src/gzip/ftgzip.c (FT_Stream_OpenGzip): Use FT_QNEW_ARRAY.
cannot handle the font file. * src/sfnt/sfobjs.c (tt_face_get_name): Use FT_QNEW_ARRAY.
* src/sfnt/ttload.c: small optimization in the kerning table * src/sfnt/ttload.c (tt_face_load_directory, tt_face_load_metrics,
verifier, speeds up TrueType face opening by about 7%. tt_face_load_gasp): Use FT_QNEW_ARRAY.
(tt_face_load_kern): Use FT_QNEW_ARRAY.
Small optimization in the kerning table verifier; this speeds up
TrueType face opening by about 7%.
(tt_face_load_hdmx): Use FT_QNEW_ARRAY and FT_QALLOC.
Also changed code to use the new FT_QNEW_ARRAY call when * include/freetype/config/ftmodule.h: Changed the order of modules,
appropriate to slightly improve performance. putting TrueType and Type 1 first. This dramatically improves the
performance of face open/close operations. For example, putting the
TrueType driver first in the list results in a 5x speedup when
opening `Vera.ttf'.
The very problem is that both the PCF and BDF drivers do a lot more
than necessary to detect that they cannot handle a font file.
2004-06-22 Werner Lemberg <wl@gnu.org> 2004-06-22 Werner Lemberg <wl@gnu.org>

View File

@ -64,6 +64,13 @@ FT_BEGIN_HEADER
const char* file_name, const char* file_name,
FT_Long line_no ); FT_Long line_no );
FT_BASE( FT_Error )
FT_QAlloc_Debug( FT_Memory memory,
FT_Long size,
void* *P,
const char* file_name,
FT_Long line_no );
FT_BASE( FT_Error ) FT_BASE( FT_Error )
FT_Realloc_Debug( FT_Memory memory, FT_Realloc_Debug( FT_Memory memory,
FT_Long current, FT_Long current,
@ -72,6 +79,14 @@ FT_BEGIN_HEADER
const char* file_name, const char* file_name,
FT_Long line_no ); FT_Long line_no );
FT_BASE( FT_Error )
FT_QRealloc_Debug( FT_Memory memory,
FT_Long current,
FT_Long size,
void* *P,
const char* file_name,
FT_Long line_no );
FT_BASE( void ) FT_BASE( void )
FT_Free_Debug( FT_Memory memory, FT_Free_Debug( FT_Memory memory,
FT_Pointer block, FT_Pointer block,
@ -114,6 +129,7 @@ FT_BEGIN_HEADER
FT_Long size, FT_Long size,
void* *p ); void* *p );
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Function> */ /* <Function> */
@ -155,6 +171,7 @@ FT_BEGIN_HEADER
FT_Long size, FT_Long size,
void* *p ); void* *p );
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Function> */ /* <Function> */
@ -330,8 +347,6 @@ FT_BEGIN_HEADER
FT_SET_ERROR( FT_MEM_QRENEW_ARRAY( _pointer_, _old_, _new_ ) ) FT_SET_ERROR( FT_MEM_QRENEW_ARRAY( _pointer_, _old_, _new_ ) )
#define FT_ALLOC_ARRAY( _pointer_, _count_, _type_ ) \ #define FT_ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
FT_SET_ERROR( FT_MEM_ALLOC( _pointer_, \ FT_SET_ERROR( FT_MEM_ALLOC( _pointer_, \
(_count_) * sizeof ( _type_ ) ) ) (_count_) * sizeof ( _type_ ) ) )

View File

@ -709,6 +709,7 @@
table->file_name = file_name; table->file_name = file_name;
table->line_no = line_no; table->line_no = line_no;
} }
return FT_QAlloc( memory, size, P ); return FT_QAlloc( memory, size, P );
} }

View File

@ -4,7 +4,7 @@
/* */ /* */
/* FreeType utility file for memory and list management (body). */ /* FreeType utility file for memory and list management (body). */
/* */ /* */
/* Copyright 2002 by */ /* Copyright 2002, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used, */ /* This file is part of the FreeType project, and may only be used, */
@ -89,7 +89,7 @@
*P = memory->alloc( memory, size ); *P = memory->alloc( memory, size );
if ( !*P ) if ( !*P )
{ {
FT_ERROR(( "FT_Alloc:" )); FT_ERROR(( "FT_QAlloc:" ));
FT_ERROR(( " Out of memory? (%ld requested)\n", FT_ERROR(( " Out of memory? (%ld requested)\n",
size )); size ));
@ -99,7 +99,7 @@
else else
*P = NULL; *P = NULL;
FT_TRACE7(( "FT_Alloc:" )); FT_TRACE7(( "FT_QAlloc:" ));
FT_TRACE7(( " size = %ld, block = 0x%08p, ref = 0x%08p\n", FT_TRACE7(( " size = %ld, block = 0x%08p, ref = 0x%08p\n",
size, *P, P )); size, *P, P ));
@ -160,9 +160,9 @@
FT_ASSERT( P != 0 ); FT_ASSERT( P != 0 );
/* if the original pointer is NULL, call FT_Alloc() */ /* if the original pointer is NULL, call FT_QAlloc() */
if ( !*P ) if ( !*P )
return FT_Alloc( memory, size, P ); return FT_QAlloc( memory, size, P );
/* if the new block if zero-sized, clear the current one */ /* if the new block if zero-sized, clear the current one */
if ( size <= 0 ) if ( size <= 0 )
@ -179,12 +179,13 @@
return FT_Err_Ok; return FT_Err_Ok;
Fail: Fail:
FT_ERROR(( "FT_Realloc:" )); FT_ERROR(( "FT_QRealloc:" ));
FT_ERROR(( " Failed (current %ld, requested %ld)\n", FT_ERROR(( " Failed (current %ld, requested %ld)\n",
current, size )); current, size ));
return FT_Err_Out_Of_Memory; return FT_Err_Out_Of_Memory;
} }
/* documentation is in ftmemory.h */ /* documentation is in ftmemory.h */
FT_BASE_DEF( void ) FT_BASE_DEF( void )

View File

@ -1716,16 +1716,19 @@
/* ensure that the kerning pair table is sorted (yes, some */ /* ensure that the kerning pair table is sorted (yes, some */
/* fonts have unsorted tables!) */ /* fonts have unsorted tables!) */
#if 1 #if 1
if ( num_pairs > 0 ) if ( num_pairs > 0 )
{ {
TT_Kern0_Pair pair0 = face->kern_pairs; TT_Kern0_Pair pair0 = face->kern_pairs;
FT_ULong prev = TT_KERN_INDEX( pair0->left, pair0->right ); FT_ULong prev = TT_KERN_INDEX( pair0->left, pair0->right );
for ( pair0++; pair0 < limit; pair0++ ) for ( pair0++; pair0 < limit; pair0++ )
{ {
FT_ULong next = TT_KERN_INDEX( pair0->left, pair0->right ); FT_ULong next = TT_KERN_INDEX( pair0->left, pair0->right );
if ( next < prev ) if ( next < prev )
goto SortIt; goto SortIt;
@ -1742,6 +1745,7 @@
TT_Kern0_Pair pair0 = face->kern_pairs; TT_Kern0_Pair pair0 = face->kern_pairs;
FT_UInt i; FT_UInt i;
for ( i = 1; i < num_pairs; i++, pair0++ ) for ( i = 1; i < num_pairs; i++, pair0++ )
{ {
if ( tt_kern_pair_compare( pair0, pair0 + 1 ) != -1 ) if ( tt_kern_pair_compare( pair0, pair0 + 1 ) != -1 )
@ -1753,6 +1757,7 @@
} }
} }
#endif #endif
goto Exit; goto Exit;
} }