aboutsummaryrefslogtreecommitdiff
path: root/strbuf.h
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-05-03 00:23:16 +0930
committerMark Pulford <mark@kyne.com.au>2011-05-03 00:23:16 +0930
commitb07c4162f4e1c5056e73500147a17f4e63abaaf4 (patch)
tree8af0d3575c205efbe4582eb5aa18e8075c535110 /strbuf.h
parentf89fb30058a7d2d6a896ace242fc612bfe4e2c34 (diff)
downloadlua-cjson-b07c4162f4e1c5056e73500147a17f4e63abaaf4.tar.gz
lua-cjson-b07c4162f4e1c5056e73500147a17f4e63abaaf4.tar.bz2
lua-cjson-b07c4162f4e1c5056e73500147a17f4e63abaaf4.zip
Add strbuf_append_number()
The separate strbuf_append_number() function avoids a potential double call to the slow vsnprintf() function required by strbuf_append_fmt(). Also inline strbuf_append_mem() since it is very simple and will be used often.
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/strbuf.h b/strbuf.h
index 9b662ef..46fad33 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -66,8 +66,9 @@ static void strbuf_ensure_empty_length(strbuf_t *s, int len);
66 66
67/* Update */ 67/* Update */
68extern void strbuf_append_fmt(strbuf_t *s, const char *format, ...); 68extern void strbuf_append_fmt(strbuf_t *s, const char *format, ...);
69extern void strbuf_append_mem(strbuf_t *s, const char *c, int len); 69static void strbuf_append_mem(strbuf_t *s, const char *c, int len);
70extern void strbuf_append_string(strbuf_t *s, const char *str); 70extern void strbuf_append_string(strbuf_t *s, const char *str);
71extern void strbuf_append_number(strbuf_t *s, double number);
71static void strbuf_append_char(strbuf_t *s, const char c); 72static void strbuf_append_char(strbuf_t *s, const char c);
72static void strbuf_ensure_null(strbuf_t *s); 73static void strbuf_ensure_null(strbuf_t *s);
73 74
@@ -100,6 +101,13 @@ static inline void strbuf_append_char_unsafe(strbuf_t *s, const char c)
100 s->buf[s->length++] = c; 101 s->buf[s->length++] = c;
101} 102}
102 103
104static inline void strbuf_append_mem(strbuf_t *s, const char *c, int len)
105{
106 strbuf_ensure_empty_length(s, len);
107 memcpy(s->buf + s->length, c, len);
108 s->length += len;
109}
110
103static inline void strbuf_ensure_null(strbuf_t *s) 111static inline void strbuf_ensure_null(strbuf_t *s)
104{ 112{
105 s->buf[s->length] = 0; 113 s->buf[s->length] = 0;