Project

General

Profile

Actions

Feature #17856

open

ary.member? is slower than ary.include?

Added by mame (Yusuke Endoh) over 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:103783]

Description

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 --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);

No data to display

Actions

Also available in: Atom PDF

Like0