Issue #17856 has been reported by mame (Yusuke Endoh).

----------------------------------------
Feature #17856: ary.member? is slower than ary.include?
https://bugs.ruby-lang.org/issues/17856

* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
----------------------------------------
`Array#include?` is defined as a faster version of `Enumerable#include?`, but there is no `Array#member?` defined.

```
$ time ruby -e 'a = (0..100000).to_a; 1000.times { a.member?(100000) }'

real    0m1.722s
user    0m1.721s
sys     0m0.000s

$ time ruby -e 'a = (0..100000).to_a; 1000.times { a.include?(100000) }'

real    0m0.524s
user    0m0.523s
sys     0m0.000s
```

I guess this is not intentional. I'll fix this issue unless there is any objection.

```diff
diff --git a/array.c b/array.c
index 881270b915..92ea9d8059 100644
--- a/array.c
+++ b/array.c
@@ -8402,6 +8402,7 @@ Init_Array(void)
     rb_define_method(rb_cArray, "clear", rb_ary_clear, 0);
     rb_define_method(rb_cArray, "fill", rb_ary_fill, -1);
     rb_define_method(rb_cArray, "include?", rb_ary_includes, 1);
+    rb_define_method(rb_cArray, "member?", rb_ary_includes, 1);
     rb_define_method(rb_cArray, "<=>", rb_ary_cmp, 1);

     rb_define_method(rb_cArray, "slice", rb_ary_aref, -1);
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>