Merge alias definition and registration

Also, make `lazy_use_super_method` hash `compare_by_identity` since
all the keys are symbols, .
This commit is contained in:
Nobuyoshi Nakada committed 2026-09-29 17:35:03 +09:00
1 parent 64a4a372d7
commit 753e64f352
3 files changed
+37 -60
Notes: git 2026-09-29 09:42:30 +00:00

No files matched your search

+28 -59
View File
@@ -4573,8 +4573,6 @@ arith_seq_size(VALUE self)
void
InitVM_Enumerator(void)
{
ID id_private = rb_intern_const("private");
rb_define_method(rb_mKernel, "to_enum", obj_to_enum, -1);
rb_define_method(rb_mKernel, "enum_for", obj_to_enum, -1);
@@ -4604,42 +4602,35 @@ InitVM_Enumerator(void)
rb_cLazy = rb_define_class_under(rb_cEnumerator, "Lazy", rb_cEnumerator);
rb_define_method(rb_mEnumerable, "lazy", enumerable_lazy, 0);
rb_define_alias(rb_cLazy, "_enumerable_map", "map");
rb_define_alias(rb_cLazy, "_enumerable_collect", "collect");
rb_define_alias(rb_cLazy, "_enumerable_flat_map", "flat_map");
rb_define_alias(rb_cLazy, "_enumerable_collect_concat", "collect_concat");
rb_define_alias(rb_cLazy, "_enumerable_select", "select");
rb_define_alias(rb_cLazy, "_enumerable_find_all", "find_all");
rb_define_alias(rb_cLazy, "_enumerable_filter", "filter");
rb_define_alias(rb_cLazy, "_enumerable_filter_map", "filter_map");
rb_define_alias(rb_cLazy, "_enumerable_reject", "reject");
rb_define_alias(rb_cLazy, "_enumerable_grep", "grep");
rb_define_alias(rb_cLazy, "_enumerable_grep_v", "grep_v");
rb_define_alias(rb_cLazy, "_enumerable_zip", "zip");
rb_define_alias(rb_cLazy, "_enumerable_take", "take");
rb_define_alias(rb_cLazy, "_enumerable_take_while", "take_while");
rb_define_alias(rb_cLazy, "_enumerable_drop", "drop");
rb_define_alias(rb_cLazy, "_enumerable_drop_while", "drop_while");
rb_define_alias(rb_cLazy, "_enumerable_uniq", "uniq");
rb_define_private_method(rb_cLazy, "_enumerable_with_index", enumerator_with_index, -1);
lazy_use_super_method = rb_ident_hash_new_capa(18);
rb_vm_register_global_object(lazy_use_super_method);
#define define_lazy_alias(name) do { \
ID name_super = rb_intern_const("_enumerable_" name); \
ID name_orig = rb_intern_const(name); \
rb_add_alias(rb_cLazy, name_super, name_orig, METHOD_VISI_PRIVATE); \
rb_hash_aset(lazy_use_super_method, ID2SYM(name_orig), ID2SYM(name_super)); \
} while (0)
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_map"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_collect"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_flat_map"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_collect_concat"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_select"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_find_all"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_filter"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_filter_map"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_reject"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_grep"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_grep_v"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_zip"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_take"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_take_while"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_drop"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_drop_while"));
rb_funcall(rb_cLazy, id_private, 1, sym("_enumerable_uniq"));
define_lazy_alias("map");
define_lazy_alias("collect");
define_lazy_alias("flat_map");
define_lazy_alias("collect_concat");
define_lazy_alias("select");
define_lazy_alias("find_all");
define_lazy_alias("filter");
define_lazy_alias("filter_map");
define_lazy_alias("reject");
define_lazy_alias("grep");
define_lazy_alias("grep_v");
define_lazy_alias("zip");
define_lazy_alias("take");
define_lazy_alias("take_while");
define_lazy_alias("drop");
define_lazy_alias("drop_while");
define_lazy_alias("uniq");
define_lazy_alias("with_index");
rb_obj_freeze(lazy_use_super_method);
rb_define_method(rb_cLazy, "initialize", lazy_initialize, -1);
rb_define_method(rb_cLazy, "to_enum", lazy_to_enum, -1);
@@ -4672,28 +4663,6 @@ InitVM_Enumerator(void)
rb_define_method(rb_cLazy, "with_index", lazy_with_index, -1);
rb_define_method(rb_cLazy, "tap_each", lazy_tap_each, 0);
lazy_use_super_method = rb_hash_new_capa(18);
rb_hash_aset(lazy_use_super_method, sym("map"), sym("_enumerable_map"));
rb_hash_aset(lazy_use_super_method, sym("collect"), sym("_enumerable_collect"));
rb_hash_aset(lazy_use_super_method, sym("flat_map"), sym("_enumerable_flat_map"));
rb_hash_aset(lazy_use_super_method, sym("collect_concat"), sym("_enumerable_collect_concat"));
rb_hash_aset(lazy_use_super_method, sym("select"), sym("_enumerable_select"));
rb_hash_aset(lazy_use_super_method, sym("find_all"), sym("_enumerable_find_all"));
rb_hash_aset(lazy_use_super_method, sym("filter"), sym("_enumerable_filter"));
rb_hash_aset(lazy_use_super_method, sym("filter_map"), sym("_enumerable_filter_map"));
rb_hash_aset(lazy_use_super_method, sym("reject"), sym("_enumerable_reject"));
rb_hash_aset(lazy_use_super_method, sym("grep"), sym("_enumerable_grep"));
rb_hash_aset(lazy_use_super_method, sym("grep_v"), sym("_enumerable_grep_v"));
rb_hash_aset(lazy_use_super_method, sym("zip"), sym("_enumerable_zip"));
rb_hash_aset(lazy_use_super_method, sym("take"), sym("_enumerable_take"));
rb_hash_aset(lazy_use_super_method, sym("take_while"), sym("_enumerable_take_while"));
rb_hash_aset(lazy_use_super_method, sym("drop"), sym("_enumerable_drop"));
rb_hash_aset(lazy_use_super_method, sym("drop_while"), sym("_enumerable_drop_while"));
rb_hash_aset(lazy_use_super_method, sym("uniq"), sym("_enumerable_uniq"));
rb_hash_aset(lazy_use_super_method, sym("with_index"), sym("_enumerable_with_index"));
rb_obj_freeze(lazy_use_super_method);
rb_vm_register_global_object(lazy_use_super_method);
#if 0 /* for RDoc */
rb_define_method(rb_cLazy, "to_a", lazy_to_a, 0);
rb_define_method(rb_cLazy, "chunk", lazy_chunk, 0);
+1
View File
@@ -263,6 +263,7 @@ void rb_method_table_insert(VALUE klass, struct rb_id_table *table, ID method_id
void rb_method_table_insert0(VALUE klass, struct rb_id_table *table, ID method_id, const rb_method_entry_t *me, bool iclass_shared_mtbl);
void rb_scope_visibility_set(rb_method_visibility_t);
void rb_add_alias(VALUE klass, ID alias_name, ID original_name, rb_method_visibility_t visi);
VALUE rb_unnamed_parameters(int arity);
+8 -1
View File
@@ -2933,7 +2933,7 @@ rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me)
}
void
rb_alias(VALUE klass, ID alias_name, ID original_name)
rb_add_alias(VALUE klass, ID alias_name, ID original_name, rb_method_visibility_t visi_alias)
{
const VALUE target_klass = klass;
VALUE defined_class;
@@ -2980,6 +2980,7 @@ rb_alias(VALUE klass, ID alias_name, ID original_name)
}
if (visi == METHOD_VISI_UNDEF) visi = METHOD_ENTRY_VISI(orig_me);
if (visi_alias != METHOD_VISI_UNDEF) visi = visi_alias;
if (!NIL_P(ruby_verbose) && rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) {
VALUE owner_class = orig_me->defined_class ? orig_me->defined_class : defined_class;
@@ -3029,6 +3030,12 @@ rb_alias(VALUE klass, ID alias_name, ID original_name)
}
}
void
rb_alias(VALUE klass, ID alias_name, ID original_name)
{
rb_add_alias(klass, alias_name, original_name, METHOD_VISI_UNDEF);
}
/*
* call-seq:
* alias_method(new_name, old_name) -> symbol