[ruby-core:32786] Re: replacing rb_intern

From: Benoit Daloze <eregontp@...>
Date: 2010-10-14 13:09:44 UTC
List: ruby-core #32786
2010/10/14 Ondřej Bílka <neleai@seznam.cz>:
> Hello
>
> I have idea to speed up ruby a bit
>
> Typical use of rb_intern looks like this
>  if (!rb_respond_to(str2, rb_intern("to_str"))) {
>              return Qfalse;
>
> which could be replaced by
>  if (!rb_respond_to(str2, id_to_str)) {
>                return Qfalse;
>
> I propose to use script which replaces all occurences of rb_intern("foo") by id_foo, defines id_foo and initializes it at Init_ function.
>
> Any comments?

AFAIK, this is already done in Ruby.
Check complex.c for example (in 1.9).

However, it is not done everywhere. One reason might be readability
("<=") and small performance gain.

It might be worth to be asked on ruby-core.

Regards,
B.D.

In This Thread