src/slist/slist.c
/*
 * Compact memory used for the slist object when the list has more than
 * SLIST_DEFAULT_SIZE free space. After the compact the list has
 * a size which is SLIST_DEFAULT_SIZE greater than its length.
 */
Compact memory used for the slist object when the list has more than
SLIST_DEFAULT_SIZE free space. After the compact the list has
a size which is SLIST_DEFAULT_SIZE greater than its length.
Compact memory used for the slist object when the list has more than SLIST_DEFAULT_SIZE free space . After the compact the list has a size which is SLIST_DEFAULT_SIZE greater than its length .
void slist_compact(slist_t ** slist)
{
    size_t sz = (*slist)->size;
    if (sz - (*slist)->len > SLIST_DEFAULT_SIZE)
    {
        slist_t * tmp;
        (*slist)->size = (*slist)->len + SLIST_DEFAULT_SIZE;
        tmp = (slist_t *) realloc(
                *slist,
                sizeof(slist_t) + sizeof(void *) * (*slist)->size);
        if (tmp == NULL)
        {
            log_error("Error has occurred while re-allocating less space");
            (*slist)->size = sz;
        }
        else
        {
            *slist = tmp;
        }
    }
}
void slist_compact ( slist_t * * slist ) { size_t sz = ( * slist ) -> size ; if ( sz - ( * slist ) -> len > SLIST_DEFAULT_SIZE ) { slist_t * tmp ; ( * slist ) -> size = ( * slist ) -> len + SLIST_DEFAULT_SIZE ; tmp = ( slist_t * ) realloc ( * slist , sizeof ( slist_t ) + sizeof ( void * ) * ( * slist ) -> size ) ; if ( tmp == NULL ) { log_error ( " " ) ; ( * slist ) -> size = sz ; } else { * slist = tmp ; } } }
Compact memory used for the slist object when the list has more than
 SLIST_DEFAULT_SIZE free space.
Compact memory used for the slist object when the list has more than SLIST_DEFAULT_SIZE free space .
/* an error has occurred; log and restore size */ /* overwrite the original value with the new one */