[autofit] Allocate hints object on the stack.

This avoids one malloc per load.

* src/autofit/afloader.h (AF_LoaderRec): Change type of `hints' to
`AF_GlyphHints'.
Update prototype.

* src/autofit/afloader.c (af_loader_init): Use `AF_GlyphHints'
parameter instead of `FT_Memory'.
(af_loader_done): Directly reset `load_hints'.
(af_loader_load_g): Updated.

* src/autofit/afmodule.c (af_autofitter_load_glyph): Use local
`hints' object.
This commit is contained in:
Behdad Esfahbod 2015-01-14 19:16:12 +01:00 committed by Werner Lemberg
parent a4117fbda7
commit c27336567b
4 changed files with 36 additions and 14 deletions

View File

@ -1,3 +1,21 @@
2015-01-14 Behdad Esfahbod <behdad@behdad.org>
[autofit] Allocate hints object on the stack.
This avoids one malloc per load.
* src/autofit/afloader.h (AF_LoaderRec): Change type of `hints' to
`AF_GlyphHints'.
Update prototype.
* src/autofit/afloader.c (af_loader_init): Use `AF_GlyphHints'
parameter instead of `FT_Memory'.
(af_loader_done): Directly reset `load_hints'.
(af_loader_load_g): Updated.
* src/autofit/afmodule.c (af_autofitter_load_glyph): Use local
`hints' object.
2015-01-14 Behdad Esfahbod <behdad@behdad.org>
[autofit] Reuse slot glyph loader.

View File

@ -27,14 +27,14 @@
/* Initialize glyph loader. */
FT_LOCAL_DEF( void )
af_loader_init( AF_Loader loader,
FT_Memory memory )
af_loader_init( AF_Loader loader,
AF_GlyphHints hints )
{
FT_ZERO( loader );
af_glyph_hints_init( &loader->hints, memory );
loader->hints = hints;
#ifdef FT_DEBUG_AUTOFIT
_af_debug_hints = &loader->hints;
_af_debug_hints = loader->hints;
#endif
}
@ -73,10 +73,9 @@
FT_LOCAL_DEF( void )
af_loader_done( AF_Loader loader )
{
af_glyph_hints_done( &loader->hints );
loader->face = NULL;
loader->globals = NULL;
loader->hints = NULL;
#ifdef FT_DEBUG_AUTOFIT
_af_debug_hints = NULL;
@ -99,7 +98,7 @@
FT_Error error;
FT_Face face = loader->face;
AF_StyleMetrics metrics = loader->metrics;
AF_GlyphHints hints = &loader->hints;
AF_GlyphHints hints = loader->hints;
FT_GlyphSlot slot = face->glyph;
FT_Slot_Internal internal = slot->internal;
FT_GlyphLoader gloader = internal->loader;
@ -398,7 +397,7 @@
if ( writing_system_class->style_hints_init )
{
error = writing_system_class->style_hints_init( &loader->hints,
error = writing_system_class->style_hints_init( loader->hints,
metrics );
if ( error )
goto Exit;

View File

@ -41,7 +41,7 @@ FT_BEGIN_HEADER
AF_FaceGlobals globals;
/* current glyph data */
AF_GlyphHintsRec hints;
AF_GlyphHints hints;
AF_StyleMetrics metrics;
FT_Bool transformed;
FT_Matrix trans_matrix;
@ -54,8 +54,8 @@ FT_BEGIN_HEADER
FT_LOCAL( void )
af_loader_init( AF_Loader loader,
FT_Memory memory );
af_loader_init( AF_Loader loader,
AF_GlyphHints hints );
FT_LOCAL( FT_Error )

View File

@ -271,18 +271,23 @@
FT_UInt glyph_index,
FT_Int32 load_flags )
{
FT_Error error = FT_Err_Ok;
AF_LoaderRec loader[1];
FT_Error error = FT_Err_Ok;
FT_Memory memory = module->root.library->memory;
AF_GlyphHintsRec hints[1];
AF_LoaderRec loader[1];
FT_UNUSED( size );
af_loader_init( loader, module->root.library->memory );
af_glyph_hints_init( hints, memory );
af_loader_init( loader, hints );
error = af_loader_load_glyph( loader, module, slot->face,
glyph_index, load_flags );
af_loader_done( loader );
af_glyph_hints_done( hints );
return error;
}