diff options
author | Jean Boussier <byroot@ruby-lang.org> | 2023-02-03 16:21:33 +0100 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2023-02-03 23:31:08 +0100 |
commit | cc9d96b259f4aca151e532d53060091114b5e39b (patch) | |
tree | da9b84f10aa95fa5c3ea740e2bf1b719afc95b27 | |
parent | 3fefe660f8e4595782f51f89277bb2054802f334 (diff) | |
download | ruby-cc9d96b259f4aca151e532d53060091114b5e39b.tar.gz |
Avoid using OBJ_WB_UNPROTECT
Not that it makes a big difference here, but it's
just unecessary.
-rw-r--r-- | struct.c | 21 |
1 files changed, 6 insertions, 15 deletions
@@ -413,18 +413,15 @@ struct_make_members_list(va_list ar) { char *mem; VALUE ary, list = rb_ident_hash_new(); - st_table *tbl = RHASH_TBL_RAW(list); - RBASIC_CLEAR_CLASS(list); - OBJ_WB_UNPROTECT(list); while ((mem = va_arg(ar, char*)) != 0) { VALUE sym = rb_sym_intern_ascii_cstr(mem); - if (st_insert(tbl, sym, Qtrue)) { + if (RTEST(rb_hash_has_key(list, sym))) { rb_raise(rb_eArgError, "duplicate member: %s", mem); } + rb_hash_aset(list, sym, Qtrue); } ary = rb_hash_keys(list); - st_clear(tbl); RBASIC_CLEAR_CLASS(ary); OBJ_FREEZE_RAW(ary); return ary; @@ -645,7 +642,6 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass) VALUE name, rest, keyword_init = Qnil; long i; VALUE st; - st_table *tbl; VALUE opt; argc = rb_scan_args(argc, argv, "1*:", NULL, NULL, &opt); @@ -675,19 +671,17 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass) rest = rb_ident_hash_new(); RBASIC_CLEAR_CLASS(rest); - OBJ_WB_UNPROTECT(rest); - tbl = RHASH_TBL_RAW(rest); for (i=0; i<argc; i++) { VALUE mem = rb_to_symbol(argv[i]); if (rb_is_attrset_sym(mem)) { rb_raise(rb_eArgError, "invalid struct member: %"PRIsVALUE, mem); } - if (st_insert(tbl, mem, Qtrue)) { + if (RTEST(rb_hash_has_key(rest, mem))) { rb_raise(rb_eArgError, "duplicate member: %"PRIsVALUE, mem); } + rb_hash_aset(rest, mem, Qtrue); } rest = rb_hash_keys(rest); - st_clear(tbl); RBASIC_CLEAR_CLASS(rest); OBJ_FREEZE_RAW(rest); if (NIL_P(name)) { @@ -1710,23 +1704,20 @@ rb_data_s_def(int argc, VALUE *argv, VALUE klass) VALUE rest; long i; VALUE data_class; - st_table *tbl; rest = rb_ident_hash_new(); RBASIC_CLEAR_CLASS(rest); - OBJ_WB_UNPROTECT(rest); - tbl = RHASH_TBL_RAW(rest); for (i=0; i<argc; i++) { VALUE mem = rb_to_symbol(argv[i]); if (rb_is_attrset_sym(mem)) { rb_raise(rb_eArgError, "invalid data member: %"PRIsVALUE, mem); } - if (st_insert(tbl, mem, Qtrue)) { + if (RTEST(rb_hash_has_key(rest, mem))) { rb_raise(rb_eArgError, "duplicate member: %"PRIsVALUE, mem); } + rb_hash_aset(rest, mem, Qtrue); } rest = rb_hash_keys(rest); - st_clear(tbl); RBASIC_CLEAR_CLASS(rest); OBJ_FREEZE_RAW(rest); data_class = anonymous_struct(klass); |