ext/json/ext/parser/parser.rl in json_pure-1.6.1 vs ext/json/ext/parser/parser.rl in json_pure-1.6.2
- old
+ new
@@ -1,5 +1,6 @@
+#include "../fbuffer/fbuffer.h"
#include "parser.h"
/* unicode */
static const char digit_values[256] = {
@@ -296,11 +297,14 @@
json->memo = p;
%% write exec;
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;
}
}
@@ -327,11 +331,14 @@
json->memo = p;
%% write exec;
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;
}
}
@@ -686,10 +693,11 @@
json->create_additions = 1;
json->create_id = rb_funcall(mJSON, i_create_id, 0);
json->object_class = Qnil;
json->array_class = Qnil;
}
+ source = rb_convert_type(source, T_STRING, "String", "to_str");
if (!json->quirks_mode) {
source = convert_encoding(StringValue(source));
}
json->current_nesting = 0;
json->len = RSTRING_LEN(source);
@@ -803,10 +811,11 @@
static JSON_Parser *JSON_allocate()
{
JSON_Parser *json = ALLOC(JSON_Parser);
MEMZERO(json, JSON_Parser, 1);
+ json->fbuffer = fbuffer_alloc(0);
return json;
}
static void JSON_mark(JSON_Parser *json)
{
@@ -817,9 +826,10 @@
rb_gc_mark_maybe(json->match_string);
}
static void JSON_free(JSON_Parser *json)
{
+ fbuffer_free(json->fbuffer);
ruby_xfree(json);
}
static VALUE cJSON_parser_s_allocate(VALUE klass)
{