ext/oj/compat.c in oj-2.9.9 vs ext/oj/compat.c in oj-2.10.0
- old
+ new
@@ -36,26 +36,32 @@
#include "resolve.h"
#include "hash.h"
#include "encode.h"
static void
-hash_set_cstr(ParseInfo pi, const char *key, size_t klen, const char *str, size_t len, const char *orig) {
- Val parent = stack_peek(&pi->stack);
+hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
+ const char *key = kval->key;
+ int klen = kval->klen;
+ Val parent = stack_peek(&pi->stack);
+ volatile VALUE rkey = kval->key_val;
- if (0 != pi->options.create_id &&
+ if (Qundef == rkey &&
+ 0 != pi->options.create_id &&
*pi->options.create_id == *key &&
pi->options.create_id_len == klen &&
0 == strncmp(pi->options.create_id, key, klen)) {
parent->classname = oj_strndup(str, len);
parent->clen = len;
} else {
volatile VALUE rstr = rb_str_new(str, len);
- volatile VALUE rkey = rb_str_new(key, klen);
- rstr = oj_encode(rstr);
- rkey = oj_encode(rkey);
- if (Yes == pi->options.sym_key) {
- rkey = rb_str_intern(rkey);
+ if (Qundef == rkey) {
+ rkey = rb_str_new(key, klen);
+ rstr = oj_encode(rstr);
+ rkey = oj_encode(rkey);
+ if (Yes == pi->options.sym_key) {
+ rkey = rb_str_intern(rkey);
+ }
}
rb_hash_aset(parent->val, rkey, rstr);
}
}