From 49ae2a69f2c3acbb952406768320401cf1769425 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 20 Jun 2020 12:49:46 +0900 Subject: Add `mrb_get_arg1()` that retrieves single (and only) argument. `mrb_get_arg1()` raises `ArgumentError` if the method does not receive one argument. And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function. --- mrbgems/mruby-struct/src/struct.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'mrbgems/mruby-struct/src/struct.c') diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index f42a5f1ea..7fbf9225f 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -154,9 +154,8 @@ mrb_struct_set_m(mrb_state *mrb, mrb_value obj) { mrb_int i = mrb_fixnum(mrb_proc_cfunc_env_get(mrb, 0)); mrb_value *ptr; - mrb_value val; + mrb_value val = mrb_get_arg1(mrb); - mrb_get_args(mrb, "o", &val); mrb_struct_modify(mrb, obj); ptr = RSTRUCT_PTR(obj); if (ptr == NULL || i >= RSTRUCT_LEN(obj)) { @@ -356,9 +355,7 @@ mrb_struct_initialize(mrb_state *mrb, mrb_value self) static mrb_value mrb_struct_init_copy(mrb_state *mrb, mrb_value copy) { - mrb_value s; - - mrb_get_args(mrb, "o", &s); + mrb_value s = mrb_get_arg1(mrb); if (mrb_obj_equal(mrb, copy, s)) return copy; if (!mrb_obj_is_instance_of(mrb, s, mrb_obj_class(mrb, copy))) { @@ -428,9 +425,8 @@ struct_aref_int(mrb_state *mrb, mrb_value s, mrb_int i) static mrb_value mrb_struct_aref(mrb_state *mrb, mrb_value s) { - mrb_value idx; + mrb_value idx = mrb_get_arg1(mrb); - mrb_get_args(mrb, "o", &idx); if (mrb_string_p(idx)) { mrb_value sym = mrb_check_intern_str(mrb, idx); @@ -545,11 +541,10 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s) static mrb_value mrb_struct_equal(mrb_state *mrb, mrb_value s) { - mrb_value s2; + mrb_value s2 = mrb_get_arg1(mrb); mrb_value *ptr, *ptr2; mrb_int i, len; - mrb_get_args(mrb, "o", &s2); if (mrb_obj_equal(mrb, s, s2)) { return mrb_true_value(); } @@ -582,11 +577,10 @@ mrb_struct_equal(mrb_state *mrb, mrb_value s) static mrb_value mrb_struct_eql(mrb_state *mrb, mrb_value s) { - mrb_value s2; + mrb_value s2 = mrb_get_arg1(mrb); mrb_value *ptr, *ptr2; mrb_int i, len; - mrb_get_args(mrb, "o", &s2); if (mrb_obj_equal(mrb, s, s2)) { return mrb_true_value(); } -- cgit v1.2.3