Commit c27336567bf9ec18734506f68fc03e328c479bc9

Behdad Esfahbod 2015-01-14T19:16:12

[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.

diff --git a/ChangeLog b/ChangeLog
index dcd6861..d2afb85 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 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.
 
 	No need to create a new glyph loader; we can reuse the one from
diff --git a/src/autofit/afloader.c b/src/autofit/afloader.c
index c407c18..c6be5ac 100644
--- 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;
diff --git a/src/autofit/afloader.h b/src/autofit/afloader.h
index 3005d00..b7eff53 100644
--- a/src/autofit/afloader.h
+++ b/src/autofit/afloader.h
@@ -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 )
diff --git a/src/autofit/afmodule.c b/src/autofit/afmodule.c
index 1eec5bb..24e0228 100644
--- 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;
   }