freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] master 9ff4153cb: [truetype] Reduce allocation scope.


From: Werner Lemberg
Subject: [freetype2] master 9ff4153cb: [truetype] Reduce allocation scope.
Date: Wed, 22 May 2024 23:43:03 -0400 (EDT)

branch: master
commit 9ff4153cbfd60491f11bb56905ce6e20e94d23c7
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    [truetype] Reduce allocation scope.
    
    * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Reduce scope
    of `points_org` and 'points_out`.
---
 src/truetype/ttgxvar.c | 45 ++++++++++++++++++++-------------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index 205310d13..0ca6cd678 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -4079,10 +4079,6 @@
     FT_UInt    glyph_index = loader->glyph_index;
     FT_UInt    n_points    = (FT_UInt)outline->n_points + 4;
 
-    FT_Vector*  points_org = NULL;  /* coordinates in 16.16 format */
-    FT_Vector*  points_out = NULL;  /* coordinates in 16.16 format */
-    FT_Bool*    has_delta  = NULL;
-
     FT_ULong  glyph_start;
 
     FT_UInt   tupleCount;
@@ -4129,17 +4125,12 @@
       return FT_Err_Ok;
     }
 
-    if ( FT_NEW_ARRAY( points_org, n_points ) ||
-         FT_NEW_ARRAY( points_out, n_points ) ||
-         FT_NEW_ARRAY( has_delta, n_points )  )
-      goto Fail1;
-
     dataSize = blend->glyphoffsets[glyph_index + 1] -
                  blend->glyphoffsets[glyph_index];
 
     if ( FT_STREAM_SEEK( blend->glyphoffsets[glyph_index] ) ||
          FT_FRAME_ENTER( dataSize )                         )
-      goto Fail1;
+      return error;
 
     glyph_start = FT_Stream_FTell( stream );
 
@@ -4189,12 +4180,6 @@
          FT_NEW_ARRAY( point_deltas_y, n_points ) )
       goto Fail3;
 
-    for ( j = 0; j < n_points; j++ )
-    {
-      points_org[j].x = FT_intToFixed( outline->points[j].x );
-      points_org[j].y = FT_intToFixed( outline->points[j].y );
-    }
-
     for ( i = 0; i < ( tupleCount & GX_TC_TUPLE_COUNT_MASK ); i++ )
     {
       FT_UInt   tupleDataSize;
@@ -4324,19 +4309,30 @@
 
       else
       {
+        FT_Vector*  points_org = NULL;  /* coordinates in 16.16 format */
+        FT_Vector*  points_out = NULL;  /* coordinates in 16.16 format */
+        FT_Bool*    has_delta  = NULL;
+
 #ifdef FT_DEBUG_LEVEL_TRACE
         int  count = 0;
 #endif
 
 
-        /* we have to interpolate the missing deltas similar to the */
-        /* IUP bytecode instruction                                 */
+        /* note that `has_delta` is set to FALSE, zeroed out */
+        if ( FT_QNEW_ARRAY( points_org, n_points ) ||
+             FT_QNEW_ARRAY( points_out, n_points ) ||
+             FT_NEW_ARRAY( has_delta, n_points )   )
+          goto Fail4;
+
         for ( j = 0; j < n_points; j++ )
         {
-          has_delta[j]  = FALSE;
-          points_out[j] = points_org[j];
+          points_org[j].x = FT_intToFixed( outline->points[j].x );
+          points_org[j].y = FT_intToFixed( outline->points[j].y );
         }
+        FT_ARRAY_COPY( points_out, points_org, n_points );
 
+        /* we have to interpolate the missing deltas similar to the */
+        /* IUP bytecode instruction                                 */
         for ( j = 0; j < point_count; j++ )
         {
           FT_UShort  idx = points[j];
@@ -4394,6 +4390,10 @@
         if ( !count )
           FT_TRACE7(( "      none\n" ));
 #endif
+      Fail4:
+        FT_FREE( points_org );
+        FT_FREE( points_out );
+        FT_FREE( has_delta );
       }
 
       if ( localpoints != ALL_POINTS )
@@ -4466,11 +4466,6 @@
 
     FT_FRAME_EXIT();
 
-  Fail1:
-    FT_FREE( points_org );
-    FT_FREE( points_out );
-    FT_FREE( has_delta );
-
     return error;
   }
 



reply via email to

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