aboutsummaryrefslogtreecommitdiff
path: root/strbuf.h
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-05-03 22:47:09 +0930
committerMark Pulford <mark@kyne.com.au>2011-05-03 22:47:09 +0930
commite1001b2f316448ce171434f31410ffc150877a82 (patch)
tree69622033d622d5ee7bafc5aaa888da345e5143a8 /strbuf.h
parent4cfafe0883da22cc020bb4e92d652ce16500b104 (diff)
downloadlua-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.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/strbuf.h b/strbuf.h
index 85f3261..7829c63 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -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
117static 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
117static inline void strbuf_ensure_null(strbuf_t *s) 123static inline void strbuf_ensure_null(strbuf_t *s)
118{ 124{
119 s->buf[s->length] = 0; 125 s->buf[s->length] = 0;