From bb8f7e7a4e6e45962dfadc3c7e840d25210dbe0f Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 4 Jan 2008 17:21:53 +0000 Subject: * include/ruby/ruby.h (rb_intern): memorize interned ID for constant string, using gcc's __builtin_constant_p and statement expression. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- include/ruby/ruby.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/ruby') diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 3f2883728..ecc9bfd92 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -719,6 +719,20 @@ const char *rb_id2name(ID); ID rb_to_id(VALUE); VALUE rb_id2str(ID); +#ifdef __GNUC__ +/* __builtin_constant_p and statement expression is available + * since gcc-2.7.2.3 at least. */ +#define rb_intern(str) \ + (__builtin_constant_p(str) ? \ + ({ \ + static ID rb_intern_id_cache; \ + if (!rb_intern_id_cache) \ + rb_intern_id_cache = rb_intern(str); \ + rb_intern_id_cache; \ + }) : \ + rb_intern(str)) +#endif + char *rb_class2name(VALUE); char *rb_obj_classname(VALUE); -- cgit