Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Aug 27, 2021
1 parent b97cefc commit 3d6bdc2
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 24 deletions.
3 changes: 1 addition & 2 deletions ext/oj/compat.c
Expand Up @@ -30,8 +30,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
if (Yes == pi->options.sym_key) {
rkey = ID2SYM(rb_intern3(key, klen, oj_utf8_encoding));
} else {
rkey = rb_str_new(key, klen);
rkey = oj_encode(rkey);
rkey = rb_utf8_str_new(key, klen);
}
} else if (Yes == pi->options.sym_key) {
rkey = oj_sym_intern(key, klen);
Expand Down
9 changes: 3 additions & 6 deletions ext/oj/custom.c
Expand Up @@ -956,16 +956,14 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
}
} else {
//volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
volatile VALUE rstr = rb_str_new(str, len);
volatile VALUE rstr = rb_utf8_str_new(str, len);

if (Qundef == rkey) {
if (Yes == pi->options.sym_key) {
rkey = ID2SYM(rb_intern3(key, klen, oj_utf8_encoding));
} else {
rkey = rb_str_new(key, klen);
rkey = oj_encode(rkey);
rkey = rb_utf8_str_new(key, klen);
}
rstr = oj_encode(rstr);
}
if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
Expand Down Expand Up @@ -1090,9 +1088,8 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
}

static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
volatile VALUE rstr = rb_str_new(str, len);
volatile VALUE rstr = rb_utf8_str_new(str, len);

rstr = oj_encode(rstr);
if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);

Expand Down
2 changes: 1 addition & 1 deletion ext/oj/mimic_json.c
Expand Up @@ -682,7 +682,7 @@ static VALUE mimic_set_create_id(VALUE self, VALUE id) {
*/
static VALUE mimic_create_id(VALUE self) {
if (NULL != oj_default_options.create_id) {
return oj_encode(rb_str_new_cstr(oj_default_options.create_id));
return rb_utf8_str_new(oj_default_options.create_id, oj_default_options.create_id_len);
}
return rb_str_new_cstr(oj_json_class);
}
Expand Down
9 changes: 3 additions & 6 deletions ext/oj/object.c
Expand Up @@ -40,8 +40,7 @@ static VALUE calc_hash_key(ParseInfo pi, Val kval, char k1) {
#if HAVE_RB_ENC_INTERNED_STR
rkey = rb_enc_interned_str(kval->key, kval->klen, oj_utf8_encoding);
#else
rkey = rb_str_new(kval->key, kval->klen);
rkey = oj_encode(rkey);
rkey = rb_utf8_str_new(kval->key, kval->klen);
OBJ_FREEZE(rkey);
#endif
return rkey;
Expand All @@ -61,8 +60,7 @@ static VALUE str_to_value(ParseInfo pi, const char *str, size_t len, const char
}
rstr = oj_circ_array_get(pi->circ_array, i);
} else {
rstr = rb_str_new(str, len);
rstr = oj_encode(rstr);
rstr = rb_utf8_str_new(str, len);
}
return rstr;
}
Expand Down Expand Up @@ -233,8 +231,7 @@ static int hat_cstr(ParseInfo pi, Val parent, Val kval, const char *str, size_t
parent->val = ID2SYM(rb_intern3(str + 1, len - 1, oj_utf8_encoding));
break;
case 's':
parent->val = rb_str_new(str, len);
parent->val = oj_encode(parent->val);
parent->val = rb_utf8_str_new(str, len);
break;
case 'c': // class
{
Expand Down
3 changes: 1 addition & 2 deletions ext/oj/wab.c
Expand Up @@ -308,8 +308,7 @@ static VALUE calc_hash_key(ParseInfo pi, Val parent) {
#if HAVE_RB_ENC_INTERNED_STR
rkey = rb_enc_interned_str(parent->key, parent->klen, oj_utf8_encoding);
#else
rkey = rb_str_new(parent->key, parent->klen);
rkey = oj_encode(rkey);
rkey = rb_utf8_str_new(parent->key, parent->klen);
rkey = rb_str_intern(rkey);
OBJ_FREEZE(rkey);
#endif
Expand Down
6 changes: 0 additions & 6 deletions notes
Expand Up @@ -12,12 +12,6 @@
- class
- need to handle auto create
- return Qundef does not store
- slot memory management
- use malloc
- for free put on atomic ptr as list
- in intern, take off and then free

- use rb_utf8_str_new(str, len) instead of oj_encode

- future
- object mode delegate
Expand Down
2 changes: 1 addition & 1 deletion test/mem.rb
Expand Up @@ -7,7 +7,7 @@

require 'oj'

Oj.default_options = { mode: :rails, cache_keys: true, cache_str: -1 }
Oj.default_options = { mode: :rails, cache_keys: false, cache_str: -1 }

def mem
`ps -o rss= -p #{$$}`.to_i
Expand Down

0 comments on commit 3d6bdc2

Please sign in to comment.