Skip to content

Commit

Permalink
no need to create buffer string unless an IO is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmario committed Oct 25, 2009
1 parent 5f4d0cf commit a0a14a3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/yajl_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,9 @@ static VALUE rb_yajl_parser_init(int argc, VALUE * argv, VALUE self) {
static VALUE rb_yajl_parser_parse(int argc, VALUE * argv, VALUE self) {
yajl_status stat;
struct yajl_parser_wrapper * wrapper;
VALUE parsed, rbufsize, input, blk;
VALUE rbufsize, input, blk;

GetParser(self, wrapper);
parsed = rb_str_new2("");

// setup our parameters
rb_scan_args(argc, argv, "11&", &input, &rbufsize, &blk);
Expand All @@ -380,6 +379,7 @@ static VALUE rb_yajl_parser_parse(int argc, VALUE * argv, VALUE self) {
if (TYPE(input) == T_STRING) {
yajl_parse_chunk((const unsigned char *)RSTRING_PTR(input), RSTRING_LEN(input), wrapper->parser);
} else if (rb_respond_to(input, intern_eof)) {
VALUE parsed = rb_str_new2("");
while (rb_funcall(input, intern_eof, 0) != Qtrue) {
rb_funcall(input, intern_io_read, 2, rbufsize, parsed);
yajl_parse_chunk((const unsigned char *)RSTRING_PTR(parsed), RSTRING_LEN(parsed), wrapper->parser);
Expand Down

0 comments on commit a0a14a3

Please sign in to comment.