ext/buffer.c in redcarpet-1.11.1 vs ext/buffer.c in redcarpet-1.11.2

- old
+ new

@@ -21,11 +21,10 @@ * * BUFFER_STATS • if defined, stats are kept about memory usage */ #define BUFFER_STDARG -#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) //16mb #include "buffer.h" #include <stdio.h> #include <stdlib.h> @@ -146,29 +145,10 @@ buffer_stat_nb += 1; buffer_stat_alloc_bytes += ret->asize; #endif return ret; } -/* bufgrow • increasing the allocated size to the given value */ -int -bufgrow(struct buf *buf, size_t neosz) { - size_t neoasz; - void *neodata; - if (!buf || !buf->unit || neosz > BUFFER_MAX_ALLOC_SIZE) return 0; - if (buf->asize >= neosz) return 1; - neoasz = buf->asize + buf->unit; - while (neoasz < neosz) neoasz += buf->unit; - neodata = realloc(buf->data, neoasz); - if (!neodata) return 0; -#ifdef BUFFER_STATS - buffer_stat_alloc_bytes += (neoasz - buf->asize); -#endif - buf->data = neodata; - buf->asize = neoasz; - return 1; } - - /* bufnew • allocation of a new buffer */ struct buf * bufnew(size_t unit) { struct buf *ret; ret = malloc(sizeof (struct buf)); @@ -214,22 +194,14 @@ void bufputs(struct buf *buf, const char *str) { bufput(buf, str, strlen (str)); } -/* bufputc • appends a single char to a buffer */ -void -bufputc(struct buf *buf, char c) { - if (!buf || !bufgrow(buf, buf->size + 1)) return; - buf->data[buf->size] = c; - buf->size += 1; } - - /* bufrelease • decrease the reference count and free the buffer if needed */ void bufrelease(struct buf *buf) { - if (!buf || !buf->unit || !buf->asize) return; + if (!buf) return; buf->ref -= 1; if (buf->ref == 0) { #ifdef BUFFER_STATS buffer_stat_nb -= 1; buffer_stat_alloc_bytes -= buf->asize; @@ -239,10 +211,10 @@ /* bufreset • frees internal data of the buffer */ void bufreset(struct buf *buf) { - if (!buf || !buf->unit || !buf->asize) return; + if (!buf) return; #ifdef BUFFER_STATS buffer_stat_alloc_bytes -= buf->asize; #endif free(buf->data); buf->data = 0;