Pillow-6.0.0/src/libImaging/GifEncode.c
/* to make things a little less complicated, we use a simple output
   queue to hold completed blocks.  the following inlined function
   adds a byte to the current block.  it allocates a new block if
   necessary. */
to make things a little less complicated, we use a simple output
queue to hold completed blocks.  the following inlined function
adds a byte to the current block.  it allocates a new block if
necessary.
to make things a little less complicated we use a simple output queue to hold completed blocks . the following inlined function adds a byte to the current block . it allocates a new block if necessary .
static inline int
emit(GIFENCODERSTATE *context, int byte)
{
    if (!context->block || context->block->size == 255) {
        GIFENCODERBLOCK* block;
        if (context->block) {
            block = context->flush;
            while (block && block->next)
                block = block->next;
            if (block)
                block->next = context->block;
            else
                context->flush = context->block;
        }
        if (context->free) {
            block = context->free;
            context->free = NULL;
        } else {
            block = malloc(sizeof(GIFENCODERBLOCK));
            if (!block)
                return 0;
        }
        block->size = 0;
        block->next = NULL;
        context->block = block;
    }
    context->block->data[context->block->size++] = byte;
    return 1;
}
static inline int emit ( GIFENCODERSTATE * context , int byte ) { if ( ! context -> block || context -> block -> size == 255 ) { GIFENCODERBLOCK * block ; if ( context -> block ) { block = context -> flush ; while ( block && block -> next ) block = block -> next ; if ( block ) block -> next = context -> block ; else context -> flush = context -> block ; } if ( context -> free ) { block = context -> free ; context -> free = NULL ; } else { block = malloc ( sizeof ( GIFENCODERBLOCK ) ) ; if ( ! block ) return 0 ; } block -> size = 0 ; block -> next = NULL ; context -> block = block ; } context -> block -> data [ context -> block -> size ++ ] = byte ; return 1 ; }
to make things a little less complicated, we use a simple output
queue to hold completed blocks.
to make things a little less complicated we use a simple output queue to hold completed blocks .
/* write a byte to the output buffer */ /* no room in the current block (or no current block);
           allocate a new one */ /* add current block to end of flush queue */ /* get a new block */ /* malloc check ok, small constant allocation */ /* write new byte to block */