diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-04 17:21:53 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-04 17:21:53 +0000 |
commit | 9eab58ee0381ac804aa1b761a088424bbfc248ad (patch) | |
tree | 4b29a35a37f21114436fcb92450dc1615c5f61d1 /include | |
parent | f3fa37e8e5743913e377ebd489cc9862f77770da (diff) | |
download | ruby-9eab58ee0381ac804aa1b761a088424bbfc248ad.tar.gz |
* include/ruby/ruby.h (rb_intern): memorize interned ID for constant
string, using gcc's __builtin_constant_p and statement expression.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r-- | include/ruby/ruby.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 3f28837281..ecc9bfd923 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); |