diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-09 09:25:32 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-09 09:25:32 +0000 |
commit | a37463ef14409c81422b3c3d6c35a0dbd21f51b7 (patch) | |
tree | 294dcb47e83e5480b1fa992aba8a4b4025c8a626 /include | |
parent | 32a51c5c95dde9e78161cccc9e75303a5523540b (diff) | |
download | ruby-a37463ef14409c81422b3c3d6c35a0dbd21f51b7.tar.gz ruby-a37463ef14409c81422b3c3d6c35a0dbd21f51b7.tar.xz ruby-a37463ef14409c81422b3c3d6c35a0dbd21f51b7.zip |
* include/ruby/ruby.h (CONST_ID): constant ID cache for non-gcc.
* *.c: no cache in init functions.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@17053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r-- | include/ruby/ruby.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 614a6145b..99321f193 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -764,17 +764,21 @@ const char *rb_id2name(ID); ID rb_to_id(VALUE); VALUE rb_id2str(ID); +#define CONST_ID_CACHE(result, str) \ + ({ \ + static ID rb_intern_id_cache; \ + if (!rb_intern_id_cache) \ + rb_intern_id_cache = (rb_intern)(str); \ + result rb_intern_id_cache; \ + }) +#define CONST_ID(var, str) \ + do {CONST_ID_CACHE(var =, str);} while (0) #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; \ - }) : \ + CONST_ID_CACHE(/**/, str) : \ rb_intern(str)) #endif |