Skip to content

Commit

Permalink
No need to pre-grow the buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed Aug 4, 2011
1 parent 9ced48d commit b5693cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions ext/redcarpet/rc_markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ static VALUE rb_redcarpet_md_render_with(VALUE self, VALUE rb_rndr, VALUE text)
if (rb_respond_to(rb_rndr, rb_intern("preprocess")))
text = rb_funcall(rb_rndr, rb_intern("preprocess"), 1, text);

Data_Get_Struct(rb_rndr, struct rb_redcarpet_rndr, rndr);

/* initialize buffers */
memset(&input_buf, 0x0, sizeof(struct buf));
input_buf.data = RSTRING_PTR(text);
input_buf.size = RSTRING_LEN(text);

output_buf = bufnew(128);
bufgrow(output_buf, RSTRING_LEN(text) * 1.4f);

Data_Get_Struct(rb_rndr, struct rb_redcarpet_rndr, rndr);

/* render the magic */
rb_redcarpet_md_flags(self, &enabled_extensions);
sd_markdown(output_buf, &input_buf, enabled_extensions, &rndr->callbacks, &rndr->options);
result = rb_str_new(output_buf->data, output_buf->size);
Expand Down
2 changes: 1 addition & 1 deletion sundown

0 comments on commit b5693cd

Please sign in to comment.