summaryrefslogtreecommitdiff
path: root/ext/json/ext/parser/parser.rl
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2011-11-23 01:02:01 +0100
committerFlorian Frank <flori@ping.de>2011-11-23 01:02:01 +0100
commit3c7ba7f2a73223b83febaaa0396bd2920adb0c11 (patch)
tree047f70df8c836c48791c2f4adcf85dced934d959 /ext/json/ext/parser/parser.rl
parent70bcd0f0ebef2808aa65d59ac77560a6fff6e5c5 (diff)
downloadjson-3c7ba7f2a73223b83febaaa0396bd2920adb0c11.tar.gz
Extract fbuffer and use it in parser and generator
Diffstat (limited to 'ext/json/ext/parser/parser.rl')
-rw-r--r--ext/json/ext/parser/parser.rl13
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index 8c4681d..f0c3b8e 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -1,3 +1,4 @@
+#include "fbuffer.h"
#include "parser.h"
/* unicode */
@@ -298,7 +299,10 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
if (cs >= JSON_integer_first_final) {
long len = p - json->memo;
- *result = rb_Integer(rb_str_new(json->memo, len));
+ fbuffer_clear(json->fbuffer);
+ fbuffer_append(json->fbuffer, json->memo, len);
+ fbuffer_append_char(json->fbuffer, '\0');
+ *result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
return p + 1;
} else {
return NULL;
@@ -329,7 +333,10 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
if (cs >= JSON_float_first_final) {
long len = p - json->memo;
- *result = rb_Float(rb_str_new(json->memo, len));
+ fbuffer_clear(json->fbuffer);
+ fbuffer_append(json->fbuffer, json->memo, len);
+ fbuffer_append_char(json->fbuffer, '\0');
+ *result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
return p + 1;
} else {
return NULL;
@@ -806,6 +813,7 @@ static JSON_Parser *JSON_allocate()
{
JSON_Parser *json = ALLOC(JSON_Parser);
MEMZERO(json, JSON_Parser, 1);
+ json->fbuffer = fbuffer_alloc(0);
return json;
}
@@ -820,6 +828,7 @@ static void JSON_mark(JSON_Parser *json)
static void JSON_free(JSON_Parser *json)
{
+ fbuffer_free(json->fbuffer);
ruby_xfree(json);
}