diff options
author | Mark Pulford <mark@kyne.com.au> | 2011-05-03 22:47:09 +0930 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2011-05-03 22:47:09 +0930 |
commit | e1001b2f316448ce171434f31410ffc150877a82 (patch) | |
tree | 69622033d622d5ee7bafc5aaa888da345e5143a8 /strbuf.h | |
parent | 4cfafe0883da22cc020bb4e92d652ce16500b104 (diff) | |
download | lua-cjson-e1001b2f316448ce171434f31410ffc150877a82.tar.gz lua-cjson-e1001b2f316448ce171434f31410ffc150877a82.tar.bz2 lua-cjson-e1001b2f316448ce171434f31410ffc150877a82.zip |
Preallocate temporary decode string buffer
The preallocated buffer removes the need for buffer length checks while
processing strings and results in a 10 - 15% speedup.
Diffstat (limited to '')
-rw-r--r-- | strbuf.h | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -114,6 +114,12 @@ static inline void strbuf_append_mem(strbuf_t *s, const char *c, int len) | |||
114 | s->length += len; | 114 | s->length += len; |
115 | } | 115 | } |
116 | 116 | ||
117 | static inline void strbuf_append_mem_unsafe(strbuf_t *s, const char *c, int len) | ||
118 | { | ||
119 | memcpy(s->buf + s->length, c, len); | ||
120 | s->length += len; | ||
121 | } | ||
122 | |||
117 | static inline void strbuf_ensure_null(strbuf_t *s) | 123 | static inline void strbuf_ensure_null(strbuf_t *s) |
118 | { | 124 | { |
119 | s->buf[s->length] = 0; | 125 | s->buf[s->length] = 0; |