diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-08-25 16:04:32 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-08-26 02:03:21 +0900 |
| commit | cec53ff77e4885de5b1fb0e81f07166a04cb8d53 (patch) | |
| tree | 6ace7131d4d596c227b94a5a1b26d5cd07864f75 /src/array.c | |
| parent | 1b545a6b635a40218a6977caede8616655de3d86 (diff) | |
| download | mruby-cec53ff77e4885de5b1fb0e81f07166a04cb8d53.tar.gz mruby-cec53ff77e4885de5b1fb0e81f07166a04cb8d53.zip | |
`Array#first` to treat 1 argument case specially to improve performance.
Diffstat (limited to 'src/array.c')
| -rw-r--r-- | src/array.c | 3 |
1 files changed, 2 insertions, 1 deletions
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"); } |
