performance optimizations regarding face opening

This commit is contained in:
David Turner 2004-06-23 15:44:03 +00:00
parent 8ef4183690
commit 5290d2fb46
9 changed files with 223 additions and 24 deletions

View File

@ -1,4 +1,6 @@
FT_USE_MODULE(autohint_module_class)
FT_USE_MODULE(tt_driver_class)
FT_USE_MODULE(t1_driver_class)
FT_USE_MODULE(cff_driver_class)
FT_USE_MODULE(t1cid_driver_class)
FT_USE_MODULE(pcf_driver_class)
@ -11,8 +13,6 @@ FT_USE_MODULE(sfnt_module_class)
FT_USE_MODULE(ft_smooth_renderer_class)
FT_USE_MODULE(ft_smooth_lcd_renderer_class)
FT_USE_MODULE(ft_smooth_lcdv_renderer_class)
FT_USE_MODULE(tt_driver_class)
FT_USE_MODULE(t1_driver_class)
FT_USE_MODULE(t42_driver_class)
FT_USE_MODULE(pfr_driver_class)
FT_USE_MODULE(winfnt_driver_class)

View File

@ -108,6 +108,11 @@ FT_BEGIN_HEADER
FT_Long size,
void* *P );
FT_BASE( FT_Error )
FT_QAlloc( FT_Memory memory,
FT_Long size,
void* *p );
/*************************************************************************/
/* */
@ -143,6 +148,12 @@ FT_BEGIN_HEADER
FT_Long size,
void* *P );
FT_BASE( FT_Error )
FT_QRealloc( FT_Memory memory,
FT_Long current,
FT_Long size,
void* *p );
/*************************************************************************/
/* */
@ -204,6 +215,14 @@ FT_BEGIN_HEADER
FT_Realloc_Debug( memory, _current_, _size_, \
(void**)&(_pointer_), __FILE__, __LINE__ )
#define FT_MEM_QALLOC( _pointer_, _size_ ) \
FT_QAlloc_Debug( memory, _size_, \
(void**)&(_pointer_), __FILE__, __LINE__ )
#define FT_MEM_QREALLOC( _pointer_, _current_, _size_ ) \
FT_QRealloc_Debug( memory, _current_, _size_, \
(void**)&(_pointer_), __FILE__, __LINE__ )
#define FT_MEM_FREE( _pointer_ ) \
FT_Free_Debug( memory, (void**)&(_pointer_), __FILE__, __LINE__ )
@ -220,6 +239,11 @@ FT_BEGIN_HEADER
#define FT_MEM_REALLOC( _pointer_, _current_, _size_ ) \
FT_Realloc( memory, _current_, _size_, (void**)&(_pointer_) )
#define FT_MEM_QALLOC( _pointer_, _size_ ) \
FT_QAlloc( memory, _size_, (void**)&(_pointer_) )
#define FT_MEM_QREALLOC( _pointer_, _current_, _size_ ) \
FT_QRealloc( memory, _current_, _size_, (void**)&(_pointer_) )
#endif /* !FT_DEBUG_MEMORY */
@ -240,6 +264,16 @@ FT_BEGIN_HEADER
FT_MEM_REALLOC( _pointer_, (_old_) * sizeof ( *(_pointer_) ), \
(_new_) * sizeof ( *(_pointer_) ) )
#define FT_MEM_QNEW( _pointer_ ) \
FT_MEM_QALLOC( _pointer_, sizeof ( *(_pointer_) ) )
#define FT_MEM_QNEW_ARRAY( _pointer_, _count_ ) \
FT_MEM_QALLOC( _pointer_, (_count_) * sizeof ( *(_pointer_) ) )
#define FT_MEM_QRENEW_ARRAY( _pointer_, _old_, _new_ ) \
FT_MEM_QREALLOC( _pointer_, (_old_) * sizeof ( *(_pointer_) ), \
(_new_) * sizeof ( *(_pointer_) ) )
/*************************************************************************/
/* */
@ -270,6 +304,13 @@ FT_BEGIN_HEADER
#define FT_FREE( _pointer_ ) \
FT_MEM_FREE( _pointer_ )
#define FT_QALLOC( _pointer_, _size_ ) \
FT_SET_ERROR( FT_MEM_QALLOC( _pointer_, _size_ ) )
#define FT_QREALLOC( _pointer_, _current_, _size_ ) \
FT_SET_ERROR( FT_MEM_QREALLOC( _pointer_, _current_, _size_ ) )
#define FT_NEW( _pointer_ ) \
FT_SET_ERROR( FT_MEM_NEW( _pointer_ ) )
@ -279,6 +320,18 @@ FT_BEGIN_HEADER
#define FT_RENEW_ARRAY( _pointer_, _old_, _new_ ) \
FT_SET_ERROR( FT_MEM_RENEW_ARRAY( _pointer_, _old_, _new_ ) )
#define FT_QNEW( _pointer_ ) \
FT_SET_ERROR( FT_MEM_QNEW( _pointer_ ) )
#define FT_QNEW_ARRAY( _pointer_, _count_ ) \
FT_SET_ERROR( FT_MEM_QNEW_ARRAY( _pointer_, _count_ ) )
#define FT_QRENEW_ARRAY( _pointer_, _old_, _new_ ) \
FT_SET_ERROR( FT_MEM_QRENEW_ARRAY( _pointer_, _old_, _new_ ) )
#define FT_ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
FT_SET_ERROR( FT_MEM_ALLOC( _pointer_, \
(_count_) * sizeof ( _type_ ) ) )

View File

@ -269,6 +269,25 @@ FT_BEGIN_HEADER
/* */
/* Each GET_xxxx() macro uses an implicit `stream' variable. */
/* */
#if 0
#define FT_GET_MACRO( type ) FT_NEXT_ ## type ( stream->cursor )
#define FT_GET_CHAR() FT_GET_MACRO( CHAR )
#define FT_GET_BYTE() FT_GET_MACRO( BYTE )
#define FT_GET_SHORT() FT_GET_MACRO( SHORT )
#define FT_GET_USHORT() FT_GET_MACRO( USHORT )
#define FT_GET_OFF3() FT_GET_MACRO( OFF3 )
#define FT_GET_UOFF3() FT_GET_MACRO( UOFF3 )
#define FT_GET_LONG() FT_GET_MACRO( LONG )
#define FT_GET_ULONG() FT_GET_MACRO( ULONG )
#define FT_GET_TAG4() FT_GET_MACRO( ULONG )
#define FT_GET_SHORT_LE() FT_GET_MACRO( SHORT_LE )
#define FT_GET_USHORT_LE() FT_GET_MACRO( USHORT_LE )
#define FT_GET_LONG_LE() FT_GET_MACRO( LONG_LE )
#define FT_GET_ULONG_LE() FT_GET_MACRO( ULONG_LE )
#else
#define FT_GET_MACRO( func, type ) ( (type)func( stream ) )
#define FT_GET_CHAR() FT_GET_MACRO( FT_Stream_GetChar, FT_Char )
@ -285,6 +304,7 @@ FT_BEGIN_HEADER
#define FT_GET_USHORT_LE() FT_GET_MACRO( FT_Stream_GetShortLE, FT_UShort )
#define FT_GET_LONG_LE() FT_GET_MACRO( FT_Stream_GetLongLE, FT_Long )
#define FT_GET_ULONG_LE() FT_GET_MACRO( FT_Stream_GetLongLE, FT_ULong )
#endif
#define FT_READ_MACRO( func, type, var ) \
( var = (type)func( stream, &error ), \

View File

@ -694,6 +694,45 @@
}
FT_BASE_DEF( FT_Error )
FT_QAlloc_Debug( FT_Memory memory,
FT_Long size,
void* *P,
const char* file_name,
FT_Long line_no )
{
FT_MemTable table = (FT_MemTable)memory->user;
if ( table )
{
table->file_name = file_name;
table->line_no = line_no;
}
return FT_QAlloc( memory, size, P );
}
FT_BASE_DEF( 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_MemTable table = (FT_MemTable)memory->user;
if ( table )
{
table->file_name = file_name;
table->line_no = line_no;
}
return FT_QRealloc( memory, current, size, P );
}
FT_BASE_DEF( void )
FT_Free_Debug( FT_Memory memory,
FT_Pointer block,

View File

@ -210,7 +210,7 @@
FT_Memory memory = stream->memory;
if ( FT_ALLOC( stream->base, count ) )
if ( FT_QALLOC( stream->base, count ) )
goto Exit;
/* read it */

View File

@ -77,6 +77,36 @@
}
FT_BASE_DEF( FT_Error )
FT_QAlloc( FT_Memory memory,
FT_Long size,
void* *P )
{
FT_ASSERT( P != 0 );
if ( size > 0 )
{
*P = memory->alloc( memory, size );
if ( !*P )
{
FT_ERROR(( "FT_Alloc:" ));
FT_ERROR(( " Out of memory? (%ld requested)\n",
size ));
return FT_Err_Out_Of_Memory;
}
}
else
*P = NULL;
FT_TRACE7(( "FT_Alloc:" ));
FT_TRACE7(( " size = %ld, block = 0x%08p, ref = 0x%08p\n",
size, *P, P ));
return FT_Err_Ok;
}
/* documentation is in ftmemory.h */
FT_BASE_DEF( FT_Error )
@ -119,6 +149,42 @@
}
FT_BASE_DEF( FT_Error )
FT_QRealloc( FT_Memory memory,
FT_Long current,
FT_Long size,
void** P )
{
void* Q;
FT_ASSERT( P != 0 );
/* if the original pointer is NULL, call FT_Alloc() */
if ( !*P )
return FT_Alloc( memory, size, P );
/* if the new block if zero-sized, clear the current one */
if ( size <= 0 )
{
FT_Free( memory, P );
return FT_Err_Ok;
}
Q = memory->realloc( memory, current, size, *P );
if ( !Q )
goto Fail;
*P = Q;
return FT_Err_Ok;
Fail:
FT_ERROR(( "FT_Realloc:" ));
FT_ERROR(( " Failed (current %ld, requested %ld)\n",
current, size ));
return FT_Err_Out_Of_Memory;
}
/* documentation is in ftmemory.h */
FT_BASE_DEF( void )

View File

@ -565,7 +565,7 @@
FT_ZERO( stream );
stream->memory = memory;
if ( !FT_NEW( zip ) )
if ( !FT_QNEW( zip ) )
{
error = ft_gzip_file_init( zip, stream, source );
if ( error )

View File

@ -267,7 +267,7 @@
FT_UNUSED( error );
if ( FT_NEW_ARRAY ( rec->string, rec->stringLength ) ||
if ( FT_QNEW_ARRAY ( rec->string, rec->stringLength ) ||
FT_STREAM_SEEK( rec->stringOffset ) ||
FT_STREAM_READ( rec->string, rec->stringLength ) )
{

View File

@ -433,7 +433,7 @@
face->num_tables = sfnt->num_tables;
if ( FT_NEW_ARRAY( face->dir_tables, face->num_tables ) )
if ( FT_QNEW_ARRAY( face->dir_tables, face->num_tables ) )
goto Exit;
if ( FT_STREAM_SEEK( sfnt->offset + 12 ) ||
@ -888,8 +888,8 @@
goto Exit;
}
if ( FT_NEW_ARRAY( *longs, num_longs ) ||
FT_NEW_ARRAY( *shorts, num_shorts ) )
if ( FT_QNEW_ARRAY( *longs, num_longs ) ||
FT_QNEW_ARRAY( *shorts, num_shorts ) )
goto Exit;
if ( FT_FRAME_ENTER( table_len ) )
@ -1586,7 +1586,7 @@
num_ranges = face->gasp.numRanges;
FT_TRACE3(( "number of ranges = %d\n", num_ranges ));
if ( FT_NEW_ARRAY( gaspranges, num_ranges ) ||
if ( FT_QNEW_ARRAY( gaspranges, num_ranges ) ||
FT_FRAME_ENTER( num_ranges * 4L ) )
goto Exit;
@ -1635,6 +1635,11 @@
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
#undef TT_KERN_INDEX
#define TT_KERN_INDEX( g1, g2 ) ( ( (FT_ULong)g1 << 16 ) | g2 )
FT_LOCAL_DEF( FT_Error )
tt_face_load_kern( TT_Face face,
FT_Stream stream )
@ -1691,8 +1696,8 @@
FT_FRAME_EXIT();
/* allocate array of kerning pairs */
if ( FT_NEW_ARRAY( face->kern_pairs, num_pairs ) ||
FT_FRAME_ENTER( 6L * num_pairs ) )
if ( FT_QNEW_ARRAY( face->kern_pairs, num_pairs ) ||
FT_FRAME_ENTER( 6L * num_pairs ) )
goto Exit;
pair = face->kern_pairs;
@ -1711,16 +1716,35 @@
/* ensure that the kerning pair table is sorted (yes, some */
/* fonts have unsorted tables!) */
#if 1
if ( num_pairs > 0 )
{
TT_Kern0_Pair pair0 = face->kern_pairs;
FT_ULong prev = TT_KERN_INDEX( pair0->left, pair0->right );
for ( pair0++; pair0 < limit; pair0++ )
{
FT_ULong next = TT_KERN_INDEX( pair0->left, pair0->right );
if ( next < prev )
goto SortIt;
prev = next;
}
goto Exit;
SortIt:
ft_qsort( (void*)face->kern_pairs, (int)num_pairs,
sizeof ( TT_Kern0_PairRec ), tt_kern_pair_compare );
}
#else
{
TT_Kern0_Pair pair0 = face->kern_pairs;
FT_UInt i;
TT_Kern0_Pair pair0;
pair0 = face->kern_pairs;
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 )
{
ft_qsort( (void*)face->kern_pairs, (int)num_pairs,
sizeof ( TT_Kern0_PairRec ), tt_kern_pair_compare );
@ -1728,7 +1752,7 @@
}
}
}
#endif
goto Exit;
}
@ -1746,10 +1770,6 @@
}
#undef TT_KERN_INDEX
#define TT_KERN_INDEX( g1, g2 ) ( ( (FT_ULong)g1 << 16 ) | g2 )
FT_CALLBACK_DEF( int )
tt_kern_pair_compare( const void* a,
const void* b )
@ -1767,6 +1787,7 @@
#undef TT_KERN_INDEX
/*************************************************************************/
@ -1820,7 +1841,7 @@
if ( hdmx->version != 0 )
goto Exit;
if ( FT_NEW_ARRAY( hdmx->records, num_records ) )
if ( FT_QNEW_ARRAY( hdmx->records, num_records ) )
goto Exit;
hdmx->num_records = num_records;
@ -1839,7 +1860,7 @@
FT_READ_BYTE( cur->max_width ) )
goto Exit;
if ( FT_ALLOC( cur->widths, num_glyphs ) ||
if ( FT_QALLOC( cur->widths, num_glyphs ) ||
FT_STREAM_READ( cur->widths, num_glyphs ) )
goto Exit;