Skip to content

Commit

Permalink
Cleaner string handling
Browse files Browse the repository at this point in the history
Use `rb_enc_copy` and define RSTRING_NOT_MODIFIED for RBX. This should
speed up things.
  • Loading branch information
vmg committed Jun 9, 2011
1 parent 42ac01b commit 777c83c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ext/redcarpet/redcarpet.c
@@ -1,6 +1,14 @@
#define RSTRING_NOT_MODIFIED

#include <stdio.h>
#include "ruby.h"

#ifdef HAVE_RUBY_ENCODING_H
#include <ruby/encoding.h>
#else
#define rb_enc_copy(dst, src)
#endif

#include "markdown.h"
#include "html.h"

Expand Down Expand Up @@ -127,11 +135,8 @@ static VALUE rb_redcarpet__render(VALUE self, RendererType render_type)
upshtml_free_renderer(&renderer);

/* force the input encoding */
if (rb_respond_to(text, rb_intern("encoding"))) {
VALUE encoding = rb_funcall(text, rb_intern("encoding"), 0);
rb_funcall(result, rb_intern("force_encoding"), 1, encoding);
}

rb_enc_copy(result, text);

return result;
}

Expand Down

0 comments on commit 777c83c

Please sign in to comment.