freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] 2 commits: * src/cache/ftcmru.c (FTC_Mr


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][master] 2 commits: * src/cache/ftcmru.c (FTC_MruList_New): Explain zeroing.
Date: Wed, 02 Feb 2022 16:44:59 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

2 changed files:

Changes:

  • src/cache/ftcmru.c
    ... ... @@ -262,6 +262,8 @@
    262 262
           if ( list->clazz.node_done )
    
    263 263
             list->clazz.node_done( node, list->data );
    
    264 264
         }
    
    265
    +
    
    266
    +    /* zero new node in case of node_init failure */
    
    265 267
         else if ( FT_ALLOC( node, list->clazz.node_size ) )
    
    266 268
           goto Exit;
    
    267 269
     
    

  • src/psaux/psobjs.c
    ... ... @@ -99,45 +99,31 @@
    99 99
       }
    
    100 100
     
    
    101 101
     
    
    102
    -  static void
    
    103
    -  shift_elements( PS_Table  table,
    
    104
    -                  FT_Byte*  old_base )
    
    105
    -  {
    
    106
    -    FT_PtrDist  delta  = table->block - old_base;
    
    107
    -    FT_Byte**   offset = table->elements;
    
    108
    -    FT_Byte**   limit  = offset + table->max_elems;
    
    109
    -
    
    110
    -
    
    111
    -    for ( ; offset < limit; offset++ )
    
    112
    -    {
    
    113
    -      if ( offset[0] )
    
    114
    -        offset[0] += delta;
    
    115
    -    }
    
    116
    -  }
    
    117
    -
    
    118
    -
    
    119 102
       static FT_Error
    
    120
    -  reallocate_t1_table( PS_Table   table,
    
    121
    -                       FT_Offset  new_size )
    
    103
    +  ps_table_realloc( PS_Table   table,
    
    104
    +                    FT_Offset  new_size )
    
    122 105
       {
    
    123 106
         FT_Memory  memory   = table->memory;
    
    124 107
         FT_Byte*   old_base = table->block;
    
    125 108
         FT_Error   error;
    
    126 109
     
    
    127 110
     
    
    128
    -    /* allocate new base block */
    
    129
    -    if ( FT_ALLOC( table->block, new_size ) )
    
    130
    -    {
    
    131
    -      table->block = old_base;
    
    111
    +    /* (re)allocate the base block */
    
    112
    +    if ( FT_REALLOC( table->block, table->capacity, new_size ) )
    
    132 113
           return error;
    
    133
    -    }
    
    134 114
     
    
    135
    -    /* copy elements and shift offsets */
    
    136
    -    if ( old_base )
    
    115
    +    /* rebase offsets if necessary */
    
    116
    +    if ( old_base && table->block != old_base )
    
    137 117
         {
    
    138
    -      FT_MEM_COPY( table->block, old_base, table->capacity );
    
    139
    -      shift_elements( table, old_base );
    
    140
    -      FT_FREE( old_base );
    
    118
    +      FT_Byte**   offset = table->elements;
    
    119
    +      FT_Byte**   limit  = offset + table->max_elems;
    
    120
    +
    
    121
    +
    
    122
    +      for ( ; offset < limit; offset++ )
    
    123
    +      {
    
    124
    +        if ( *offset )
    
    125
    +          *offset = table->block + ( *offset - old_base );
    
    126
    +      }
    
    141 127
         }
    
    142 128
     
    
    143 129
         table->capacity = new_size;
    
    ... ... @@ -204,7 +190,7 @@
    204 190
             new_size  = FT_PAD_CEIL( new_size, 1024 );
    
    205 191
           }
    
    206 192
     
    
    207
    -      error = reallocate_t1_table( table, new_size );
    
    193
    +      error = ps_table_realloc( table, new_size );
    
    208 194
           if ( error )
    
    209 195
             return error;
    
    210 196
     
    
    ... ... @@ -234,30 +220,12 @@
    234 220
        * @InOut:
    
    235 221
        *   table ::
    
    236 222
        *     The target table.
    
    237
    -   *
    
    238
    -   * @Note:
    
    239
    -   *   This function does NOT release the heap's memory block.  It is up
    
    240
    -   *   to the caller to clean it, or reference it in its own structures.
    
    241 223
        */
    
    242 224
       FT_LOCAL_DEF( void )
    
    243 225
       ps_table_done( PS_Table  table )
    
    244 226
       {
    
    245
    -    FT_Memory  memory = table->memory;
    
    246
    -    FT_Error   error;
    
    247
    -    FT_Byte*   old_base = table->block;
    
    248
    -
    
    249
    -
    
    250
    -    /* should never fail, because rec.cursor <= rec.size */
    
    251
    -    if ( !old_base )
    
    252
    -      return;
    
    253
    -
    
    254
    -    if ( FT_QALLOC( table->block, table->cursor ) )
    
    255
    -      return;
    
    256
    -    FT_MEM_COPY( table->block, old_base, table->cursor );
    
    257
    -    shift_elements( table, old_base );
    
    258
    -
    
    259
    -    table->capacity = table->cursor;
    
    260
    -    FT_FREE( old_base );
    
    227
    +    /* no problem if shrinking fails */
    
    228
    +    ps_table_realloc( table, table->cursor );
    
    261 229
       }
    
    262 230
     
    
    263 231
     
    


  • reply via email to

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