ref: c27336567bf9ec18734506f68fc03e328c479bc9
parent: a4117fbda7399e201d4e438d301ab588d28dcea7
author: Behdad Esfahbod <[email protected]>
date: Wed Jan 14 14:16:12 EST 2015
[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.
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
2015-01-14 Behdad Esfahbod <[email protected]>
+ [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 <[email protected]>
+
[autofit] Reuse slot glyph loader.
No need to create a new glyph loader; we can reuse the one from
--- a/src/autofit/afloader.c
+++ b/src/autofit/afloader.c
@@ -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;
--- a/src/autofit/afloader.h
+++ b/src/autofit/afloader.h
@@ -41,7 +41,7 @@
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_LOCAL( void )
- af_loader_init( AF_Loader loader,
- FT_Memory memory );
+ af_loader_init( AF_Loader loader,
+ AF_GlyphHints hints );
FT_LOCAL( FT_Error )
--- a/src/autofit/afmodule.c
+++ b/src/autofit/afmodule.c
@@ -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;
}