[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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
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;
}