From cec53ff77e4885de5b1fb0e81f07166a04cb8d53 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 25 Aug 2017 16:04:32 +0900 Subject: `Array#first` to treat 1 argument case specially to improve performance. --- src/array.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/array.c') diff --git a/src/array.c b/src/array.c index be6744724..3ccdd3262 100644 --- a/src/array.c +++ b/src/array.c @@ -931,9 +931,10 @@ mrb_ary_first(mrb_state *mrb, mrb_value self) struct RArray *a = mrb_ary_ptr(self); mrb_int size, alen = ARY_LEN(a); - if (mrb_get_args(mrb, "|i", &size) == 0) { + if (mrb->c->ci->argc == 0) { return (alen > 0)? ARY_PTR(a)[0]: mrb_nil_value(); } + mrb_get_args(mrb, "|i", &size); if (size < 0) { mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array size"); } -- cgit v1.2.3