Skip to content

Commit

Permalink
Delegate string allocation to Ruby
Browse files Browse the repository at this point in the history
This commit replaces
- allocation with malloc(3)
- intern'ed string generation
with
- allocation by Ruby String (hence no more free(3) needed)
- String#to_sym
  • Loading branch information
d committed Jun 4, 2014
1 parent c9c6884 commit ec507ea
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions ext/yajl/yajl_ext.c
Expand Up @@ -316,16 +316,12 @@ static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsi
#endif

if (wrapper->symbolizeKeys) {
char* buf = (char*)malloc(stringLen+1);
memcpy(buf, stringVal, stringLen);
buf[stringLen] = 0;
VALUE stringEncoded = rb_str_new2(buf);
free(buf);
VALUE stringEncoded = rb_str_new((const char *)stringVal, stringLen);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(stringEncoded, rb_utf8_encoding());
#endif

yajl_set_static_value(ctx, ID2SYM(rb_to_id(stringEncoded)));
yajl_set_static_value(ctx, rb_str_intern(stringEncoded));
} else {
keyStr = rb_str_new((const char *)stringVal, stringLen);
#ifdef HAVE_RUBY_ENCODING_H
Expand Down

0 comments on commit ec507ea

Please sign in to comment.