Skip to content

Commit e5f468c

Browse files
committed
skip creating intermediate ruby string for symbol keys on 1.9+
1 parent 5ebf341 commit e5f468c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ext/mysql2/result.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,18 @@ static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int
114114

115115
field = mysql_fetch_field_direct(wrapper->result, idx);
116116
if (symbolize_keys) {
117-
VALUE colStr;
118117
char buf[field->name_length+1];
119118
memcpy(buf, field->name, field->name_length);
120119
buf[field->name_length] = 0;
121-
colStr = rb_str_new2(buf);
120+
122121
#ifdef HAVE_RUBY_ENCODING_H
123-
rb_enc_associate(colStr, rb_utf8_encoding());
124-
#endif
122+
rb_field = rb_intern3(buf, field->name_length, rb_utf8_encoding());
123+
rb_field = ID2SYM(rb_field);
124+
#else
125+
VALUE colStr;
126+
colStr = rb_str_new2(buf);
125127
rb_field = ID2SYM(rb_to_id(colStr));
128+
#endif
126129
} else {
127130
rb_field = rb_str_new(field->name, field->name_length);
128131
#ifdef HAVE_RUBY_ENCODING_H

0 commit comments

Comments
 (0)