Changeset d8d8f20


Ignore:
Timestamp:
Jul 21, 2020, 11:18:26 AM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
4a32319
Parents:
2b23d78
Message:

remove one unnecessary call to malloc_size in alloc_set and alloc_align_set

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.hfa

    r2b23d78 rd8d8f20  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul 20 19:04:33 2020
    13 // Update Count     : 472
     12// Last Modified On : Tue Jul 21 07:58:05 2020
     13// Update Count     : 475
    1414//
    1515
     
    163163        T * alloc_set( T ptr[], size_t dim, char fill ) {       // realloc array with fill
    164164                size_t osize = malloc_size( ptr );                              // current allocation
    165                 T * nptr = realloc( ptr, dim * sizeof(T) );             // CFA realloc
    166                 size_t nsize = malloc_size( nptr );                             // new allocation
     165                size_t nsize = dim * sizeof(T);                                 // new allocation
     166                T * nptr = realloc( ptr, nsize );                               // CFA realloc
    167167                if ( nsize > osize ) {                                                  // larger ?
    168168                        memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
     
    172172
    173173        T * alloc_set( T ptr[], size_t dim, T & fill ) {        // realloc array with fill
    174                 size_t odim = malloc_size( ptr ) / sizeof(T);   // current allocation
    175                 T * nptr = realloc( ptr, dim * sizeof(T) );             // CFA realloc
    176                 size_t ndim = malloc_size( nptr ) / sizeof(T);  // new allocation
     174                size_t odim = malloc_size( ptr ) / sizeof(T);   // current dimension
     175                size_t nsize = dim * sizeof(T);                                 // new allocation
     176                size_t ndim = nsize / sizeof(T);                                // new dimension
     177                T * nptr = realloc( ptr, nsize );                               // CFA realloc
    177178                if ( ndim > odim ) {                                                    // larger ?
    178179                        for ( i; odim ~ ndim ) {
     
    230231        T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ) {
    231232                size_t osize = malloc_size( ptr );                              // current allocation
    232                 T * nptr = realloc( ptr, align, dim * sizeof(T) ); // CFA realloc
    233                 size_t nsize = malloc_size( nptr );                             // new allocation
     233                size_t nsize = dim * sizeof(T);                                 // new allocation
     234                T * nptr = realloc( ptr, align, nsize );                // CFA realloc
    234235                if ( nsize > osize ) {                                                  // larger ?
    235236                        memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
     
    239240
    240241        T * alloc_align_set( T ptr[], size_t align, size_t dim, T & fill ) {
    241                 size_t odim = malloc_size( ptr ) / sizeof(T);   // current allocation
    242                 T * nptr = realloc( ptr, align, dim * sizeof(T) ); // CFA realloc
    243                 size_t ndim = malloc_size( nptr );                              // new allocation
     242                size_t odim = malloc_size( ptr ) / sizeof(T);   // current dimension
     243                size_t nsize = dim * sizeof(T);                                 // new allocation
     244                size_t ndim = nsize / sizeof(T);                                // new dimension
     245                T * nptr = realloc( ptr, align, nsize );                // CFA realloc
    244246                if ( ndim > odim ) {                                                    // larger ?
    245247                        for ( i; odim ~ ndim ) {
Note: See TracChangeset for help on using the changeset viewer.