зеркало из https://github.com/github/ruby.git
Rewrite Symbol#to_sym and #intern in Ruby (#6683)
This commit is contained in:
Родитель
41b0f641ef
Коммит
e7443dbbca
|
@ -23,6 +23,7 @@ nilclass.rb
|
|||
pack.rb
|
||||
ractor.rb
|
||||
string.rb
|
||||
symbol.rb
|
||||
timev.rb
|
||||
thread_sync.rb
|
||||
trace_point.rb
|
||||
|
|
|
@ -1104,6 +1104,7 @@ BUILTIN_RB_SRCS = \
|
|||
$(srcdir)/array.rb \
|
||||
$(srcdir)/kernel.rb \
|
||||
$(srcdir)/ractor.rb \
|
||||
$(srcdir)/symbol.rb \
|
||||
$(srcdir)/timev.rb \
|
||||
$(srcdir)/thread_sync.rb \
|
||||
$(srcdir)/nilclass.rb \
|
||||
|
@ -9600,6 +9601,7 @@ miniinit.$(OBJEXT): {$(VPATH)}ruby_atomic.h
|
|||
miniinit.$(OBJEXT): {$(VPATH)}shape.h
|
||||
miniinit.$(OBJEXT): {$(VPATH)}st.h
|
||||
miniinit.$(OBJEXT): {$(VPATH)}subst.h
|
||||
miniinit.$(OBJEXT): {$(VPATH)}symbol.rb
|
||||
miniinit.$(OBJEXT): {$(VPATH)}thread_$(THREAD_MODEL).h
|
||||
miniinit.$(OBJEXT): {$(VPATH)}thread_native.h
|
||||
miniinit.$(OBJEXT): {$(VPATH)}thread_sync.rb
|
||||
|
@ -15425,6 +15427,7 @@ symbol.$(OBJEXT): {$(VPATH)}backward/2/limits.h
|
|||
symbol.$(OBJEXT): {$(VPATH)}backward/2/long_long.h
|
||||
symbol.$(OBJEXT): {$(VPATH)}backward/2/stdalign.h
|
||||
symbol.$(OBJEXT): {$(VPATH)}backward/2/stdarg.h
|
||||
symbol.$(OBJEXT): {$(VPATH)}builtin.h
|
||||
symbol.$(OBJEXT): {$(VPATH)}config.h
|
||||
symbol.$(OBJEXT): {$(VPATH)}constant.h
|
||||
symbol.$(OBJEXT): {$(VPATH)}debug_counter.h
|
||||
|
@ -15597,6 +15600,8 @@ symbol.$(OBJEXT): {$(VPATH)}st.h
|
|||
symbol.$(OBJEXT): {$(VPATH)}subst.h
|
||||
symbol.$(OBJEXT): {$(VPATH)}symbol.c
|
||||
symbol.$(OBJEXT): {$(VPATH)}symbol.h
|
||||
symbol.$(OBJEXT): {$(VPATH)}symbol.rb
|
||||
symbol.$(OBJEXT): {$(VPATH)}symbol.rbinc
|
||||
symbol.$(OBJEXT): {$(VPATH)}vm_debug.h
|
||||
symbol.$(OBJEXT): {$(VPATH)}vm_sync.h
|
||||
thread.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
|
||||
|
|
1
inits.c
1
inits.c
|
@ -99,6 +99,7 @@ rb_call_builtin_inits(void)
|
|||
BUILTIN(warning);
|
||||
BUILTIN(array);
|
||||
BUILTIN(kernel);
|
||||
BUILTIN(symbol);
|
||||
BUILTIN(timev);
|
||||
BUILTIN(thread_sync);
|
||||
BUILTIN(yjit);
|
||||
|
|
19
string.c
19
string.c
|
@ -11524,23 +11524,6 @@ rb_sym_to_s(VALUE sym)
|
|||
return str_new_shared(rb_cString, rb_sym2str(sym));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* to_sym -> self
|
||||
*
|
||||
* Returns +self+.
|
||||
*
|
||||
* Symbol#intern is an alias for Symbol#to_sym.
|
||||
*
|
||||
* Related: String#to_sym.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
sym_to_sym(VALUE sym)
|
||||
{
|
||||
return sym;
|
||||
}
|
||||
|
||||
MJIT_FUNC_EXPORTED VALUE
|
||||
rb_sym_proc_call(ID mid, int argc, const VALUE *argv, int kw_splat, VALUE passed_proc)
|
||||
{
|
||||
|
@ -12107,8 +12090,6 @@ Init_String(void)
|
|||
rb_define_method(rb_cSymbol, "to_s", rb_sym_to_s, 0);
|
||||
rb_define_method(rb_cSymbol, "id2name", rb_sym_to_s, 0);
|
||||
rb_define_method(rb_cSymbol, "name", rb_sym2str, 0); /* in symbol.c */
|
||||
rb_define_method(rb_cSymbol, "intern", sym_to_sym, 0);
|
||||
rb_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0);
|
||||
rb_define_method(rb_cSymbol, "to_proc", rb_sym_to_proc, 0); /* in proc.c */
|
||||
rb_define_method(rb_cSymbol, "succ", sym_succ, 0);
|
||||
rb_define_method(rb_cSymbol, "next", sym_succ, 0);
|
||||
|
|
2
symbol.c
2
symbol.c
|
@ -22,6 +22,7 @@
|
|||
#include "ruby/st.h"
|
||||
#include "symbol.h"
|
||||
#include "vm_sync.h"
|
||||
#include "builtin.h"
|
||||
|
||||
#ifndef USE_SYMBOL_GC
|
||||
# define USE_SYMBOL_GC 1
|
||||
|
@ -1262,3 +1263,4 @@ rb_is_local_name(VALUE name)
|
|||
}
|
||||
|
||||
#include "id_table.c"
|
||||
#include "symbol.rbinc"
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
class Symbol
|
||||
# call-seq:
|
||||
# to_sym -> self
|
||||
#
|
||||
# Returns +self+.
|
||||
#
|
||||
# Symbol#intern is an alias for Symbol#to_sym.
|
||||
#
|
||||
# Related: String#to_sym.
|
||||
def to_sym
|
||||
self
|
||||
end
|
||||
|
||||
alias intern to_sym
|
||||
end
|
Загрузка…
Ссылка в новой задаче