freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft-devel] ttinterp.c optimization


From: Alexei Podtelezhnikov
Subject: Re: [ft-devel] ttinterp.c optimization
Date: Mon, 1 Sep 2014 23:10:09 -0400

On Wed, Aug 27, 2014 at 12:42 AM, Werner LEMBERG <address@hidden> wrote:
>
> Measuring ppem and pt values are done along the projection vector, so
> they *must* be recomputed each time since this value can change any
> time.  However, it certainly makes sense to catch factor `1.0'
> explicitly instead of performing a multiplication.  So please
> optimize :-)

So after some additional discussions with Werner, I came up with the
following patch, which speeds up FT_New_Face for Arial and Times by
huge 18% and 27% respectively.

diff --git a/src/truetype/ttinterp.h b/src/truetype/ttinterp.h
index 1d8825d..48a65a2 100644
--- a/src/truetype/ttinterp.h
+++ b/src/truetype/ttinterp.h
@@ -81,6 +81,10 @@ FT_BEGIN_HEADER
   (*TT_Project_Func)( EXEC_OP_ FT_Pos   dx,
                                FT_Pos   dy );

+  /* getting current ppem.  Take care of non-square pixels if necessary */
+  typedef FT_Long
+  (*TT_Cur_Ppem_Func)( EXEC_OP );
+
   /* reading a cvt value.  Take care of non-square pixels if necessary */
   typedef FT_F26Dot6
   (*TT_Get_CVT_Func)( EXEC_OP_ FT_ULong  idx );
@@ -254,6 +258,8 @@ FT_BEGIN_HEADER
     TT_Move_Func       func_move;      /* current point move function */
     TT_Move_Func       func_move_orig; /* move original position function */

+    TT_Cur_Ppem_Func   func_cur_ppem;  /* get current ppem value        */
+
     TT_Get_CVT_Func    func_read_cvt;  /* read a cvt entry              */
     TT_Set_CVT_Func    func_write_cvt; /* write a cvt entry (in pixels) */
     TT_Set_CVT_Func    func_move_cvt;  /* incr a cvt entry (in pixels)  */
diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c
index 1f8debf..dbf64e6 100644
--- a/src/truetype/ttinterp.c
+++ b/src/truetype/ttinterp.c
@@ -172,6 +172,9 @@
 #define CUR_Func_round( d, c ) \
           CUR.func_round( EXEC_ARG_ d, c )

+#define CUR_Func_cur_ppem() \
+          CUR.func_cur_ppem( EXEC_ARG )
+
 #define CUR_Func_read_cvt( index ) \
           CUR.func_read_cvt( EXEC_ARG_ index )

@@ -184,12 +187,6 @@
 #define CURRENT_Ratio() \
           Current_Ratio( EXEC_ARG )

-#define CURRENT_Ppem() \
-          Current_Ppem( EXEC_ARG )
-
-#define CUR_Ppem() \
-          Cur_PPEM( EXEC_ARG )
-
 #define INS_SxVTL( a, b, c, d ) \
           Ins_SxVTL( EXEC_ARG_ a, b, c, d )

@@ -1706,9 +1703,16 @@
   }


-  static FT_Long
+  FT_CALLBACK_DEF( FT_Long )
   Current_Ppem( EXEC_OP )
   {
+    return CUR.tt_metrics.ppem;
+  }
+
+
+  FT_CALLBACK_DEF( FT_Long )
+  Current_Ppem_Stretched( EXEC_OP )
+  {
     return FT_MulFix( CUR.tt_metrics.ppem, CURRENT_Ratio() );
   }
 @@ -3089,7 +3093,7 @@


 #define DO_MPPEM              \
-    args[0] = CURRENT_Ppem();
+    args[0] = CUR_Func_cur_ppem();


   /* Note: The pointSize should be irrelevant in a given font program; */
@@ -3102,7 +3106,7 @@
 #else

 #define DO_MPS                \
-    args[0] = CURRENT_Ppem();
+    args[0] = CUR_Func_cur_ppem();

 #endif /* 0 */

@@ -7523,7 +7527,7 @@
     }
 #endif

-    P = (FT_ULong)CURRENT_Ppem();
+    P = (FT_ULong)CUR_Func_cur_ppem();
     nump = (FT_ULong)args[0];   /* some points theoretically may occur more
                                    than once, thus UShort isn't enough */

@@ -7692,7 +7696,7 @@
     }
 #endif

-    P = (FT_ULong)CURRENT_Ppem();
+    P = (FT_ULong)CUR_Func_cur_ppem();
     nump = (FT_ULong)args[0];

     for ( k = 1; k <= nump; k++ )
@@ -8276,6 +8280,7 @@
     if ( CUR.metrics.x_ppem != CUR.metrics.y_ppem )
     {
       /* non-square pixels, use the stretched routines */
+      CUR.func_cur_ppem  = Current_Ppem_Stretched;
       CUR.func_read_cvt  = Read_CVT_Stretched;
       CUR.func_write_cvt = Write_CVT_Stretched;
       CUR.func_move_cvt  = Move_CVT_Stretched;
@@ -8283,6 +8288,7 @@
     else
     {
       /* square pixels, use normal routines */
+      CUR.func_cur_ppem  = Current_Ppem;
       CUR.func_read_cvt  = Read_CVT;
       CUR.func_write_cvt = Write_CVT;
       CUR.func_move_cvt  = Move_CVT;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]