summaryrefslogtreecommitdiffhomepage
path: root/src/array.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-08-25 16:04:32 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-08-26 02:03:21 +0900
commitcec53ff77e4885de5b1fb0e81f07166a04cb8d53 (patch)
tree6ace7131d4d596c227b94a5a1b26d5cd07864f75 /src/array.c
parent1b545a6b635a40218a6977caede8616655de3d86 (diff)
downloadmruby-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.c3
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");
}