ruby-changes:8985
From: nobu <ko1@a...>
Date: Fri, 5 Dec 2008 00:18:24 +0900 (JST)
Subject: [ruby-changes:8985] Ruby:r20521 (trunk): * string.c (sym_to_proc): caches Symbol procs, based on a patch from
nobu 2008-12-05 00:17:21 +0900 (Fri, 05 Dec 2008) New Revision: 20521 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20521 Log: * string.c (sym_to_proc): caches Symbol procs, based on a patch from Shumpei Akai <admin AT flexfrank.net>. [ruby-dev:37265] Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 20520) +++ ChangeLog (revision 20521) @@ -1,3 +1,8 @@ +Fri Dec 5 00:17:18 2008 Nobuyoshi Nakada <nobu@r...> + + * string.c (sym_to_proc): caches Symbol procs, based on a patch from + Shumpei Akai <admin AT flexfrank.net>. [ruby-dev:37265] + Thu Dec 4 23:29:34 2008 NAKAMURA Usaku <usa@r...> * win32/win32.c (waitpid): fix bug of checking child slot. Index: string.c =================================================================== --- string.c (revision 20520) +++ string.c (revision 20521) @@ -6915,10 +6915,33 @@ static VALUE sym_to_proc(VALUE sym) { - return rb_proc_new(sym_call, (VALUE)SYM2ID(sym)); + static VALUE sym_proc_cache = Qfalse; + enum {SYM_PROC_CACHE_SIZE = 67}; + VALUE proc; + long id, index; + VALUE *aryp; + + if (!sym_proc_cache) { + rb_gc_register_mark_object(sym_proc_cache); + sym_proc_cache = rb_ary_new2(SYM_PROC_CACHE_SIZE * 2); + rb_ary_store(sym_proc_cache, SYM_PROC_CACHE_SIZE*2 - 1, Qnil); + } + + id = SYM2ID(sym); + index = (id % SYM_PROC_CACHE_SIZE) << 1; + + aryp = RARRAY_PTR(sym_proc_cache); + if (aryp[index] == sym) { + return aryp[index + 1]; + } + else { + proc = rb_proc_new(sym_call, (VALUE)id); + aryp[index] = sym; + aryp[index + 1] = proc; + return proc; + } } - static VALUE sym_succ(VALUE sym) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/