mirror of
https://github.com/ruby/ruby.git
synced 2025-09-21 03:24:00 +02:00
* include/ruby/ruby.h (CONST_ID): constant ID cache for non-gcc.
* *.c: no cache in init functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
250dd07021
commit
5a647a3f5f
32 changed files with 141 additions and 85 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue