summaryrefslogtreecommitdiff
path: root/ext/standard/php_smart_str.h
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2001-08-03 07:25:27 +0000
committerSascha Schumann <sas@php.net>2001-08-03 07:25:27 +0000
commit4dfa91543ce8ed38d1ada5f8ffacd73a9984c5e5 (patch)
tree7c4872e1a819f904348c8a60e27d5a5e9e50ac70 /ext/standard/php_smart_str.h
parent2ec440078a74d86a0ddcd0818bc37d21bfe98082 (diff)
downloadphp-git-4dfa91543ce8ed38d1ada5f8ffacd73a9984c5e5.tar.gz
Convert serializer to smart_str.. avoids lots of sprintf's and
copying of data.
Diffstat (limited to 'ext/standard/php_smart_str.h')
-rw-r--r--ext/standard/php_smart_str.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h
index 4681b4a663..8146a057d3 100644
--- a/ext/standard/php_smart_str.h
+++ b/ext/standard/php_smart_str.h
@@ -46,6 +46,7 @@
#define smart_str_free(s) smart_str_free_ex(s, 0)
#define smart_str_appendl(dest,src,len) smart_str_appendl_ex(dest,src,len,0)
#define smart_str_append(dest, src) smart_str_append_ex(dest,src,0)
+#define smart_str_append_long(dest, val) smart_str_append_long_ex(dest,val,0)
static inline void smart_str_appendc_ex(smart_str *dest, char c, int what)
{
@@ -75,6 +76,36 @@ static inline void smart_str_appendl_ex(smart_str *dest, const char *src, size_t
dest->len = newlen;
}
+static inline char *smart_str_print_long(char *buf, long num)
+{
+ char *p = buf;
+ long tmp = 0;
+
+ if (num < 0) {
+ num = -num;
+ *p++ = '-';
+ }
+
+ while (num > 0) {
+ tmp = tmp * 10 + (num % 10);
+ num /= 10;
+ }
+
+ do {
+ *p++ = (tmp % 10) + '0';
+ tmp /= 10;
+ } while (tmp > 0);
+
+ return p;
+}
+
+static inline void smart_str_append_long_ex(smart_str *dest, long num, int type)
+{
+ char buf[32];
+ char *p = smart_str_print_long(buf, num);
+ smart_str_appendl_ex(dest, buf, p - buf, type);
+}
+
static inline void smart_str_append_ex(smart_str *dest, smart_str *src, int what)
{
smart_str_appendl_ex(dest, src->c, src->len, what);