diff options
| author | Mark Pulford <mark@kyne.com.au> | 2011-04-25 00:56:55 +0930 |
|---|---|---|
| committer | Mark Pulford <mark@kyne.com.au> | 2011-04-25 00:56:55 +0930 |
| commit | 85f2231b381a232686a39e4962b3d5e3cad61161 (patch) | |
| tree | a4f91a37496af94a7bbfcdac268296e9dbb2679b /strbuf.h | |
| parent | 2b693fb4493764e71f11b6257c0ce58cdbb8a779 (diff) | |
| download | lua-cjson-85f2231b381a232686a39e4962b3d5e3cad61161.tar.gz lua-cjson-85f2231b381a232686a39e4962b3d5e3cad61161.tar.bz2 lua-cjson-85f2231b381a232686a39e4962b3d5e3cad61161.zip | |
Add support for growing strbufs exponentially
- Change default to 1024 byte strings and doubling in size
- Add strbuf debug statistics
Diffstat (limited to '')
| -rw-r--r-- | strbuf.h | 11 |
1 files changed, 8 insertions, 3 deletions
| @@ -13,15 +13,20 @@ typedef struct { | |||
| 13 | int length; | 13 | int length; |
| 14 | int increment; | 14 | int increment; |
| 15 | int dynamic; | 15 | int dynamic; |
| 16 | int reallocs; | ||
| 17 | int debug; | ||
| 16 | } strbuf_t; | 18 | } strbuf_t; |
| 17 | 19 | ||
| 20 | #ifndef STRBUF_DEFAULT_SIZE | ||
| 21 | #define STRBUF_DEFAULT_SIZE 1023 | ||
| 22 | #endif | ||
| 18 | #ifndef STRBUF_DEFAULT_INCREMENT | 23 | #ifndef STRBUF_DEFAULT_INCREMENT |
| 19 | #define STRBUF_DEFAULT_INCREMENT 8 | 24 | #define STRBUF_DEFAULT_INCREMENT -2 |
| 20 | #endif | 25 | #endif |
| 21 | 26 | ||
| 22 | /* Initialise */ | 27 | /* Initialise */ |
| 23 | extern strbuf_t *strbuf_new(); | 28 | extern strbuf_t *strbuf_new(int len); |
| 24 | extern void strbuf_init(strbuf_t *s); | 29 | extern void strbuf_init(strbuf_t *s, int len); |
| 25 | extern void strbuf_set_increment(strbuf_t *s, int increment); | 30 | extern void strbuf_set_increment(strbuf_t *s, int increment); |
| 26 | 31 | ||
| 27 | /* Release */ | 32 | /* Release */ |
