* include/ruby/ruby.h (RB_LIKELY): use prefix in ruby.h.

* intern.h (LIKELY): define with RB_LIKELY.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2016-04-23 07:15:25 +00:00
parent 3f7cce9f18
commit 5587badf24
3 changed files with 18 additions and 9 deletions

View File

@ -1,3 +1,9 @@
Sat Apr 23 16:10:02 2016 NARUSE, Yui <naruse@ruby-lang.org>
* include/ruby/ruby.h (RB_LIKELY): use prefix in ruby.h.
* intern.h (LIKELY): define with RB_LIKELY.
Sat Apr 23 13:27:25 2016 Yuichiro Kaneko <yui-knk@ruby-lang.org> Sat Apr 23 13:27:25 2016 Yuichiro Kaneko <yui-knk@ruby-lang.org>
* NEWS: Add descriptions for Time#to_time updates. * NEWS: Add descriptions for Time#to_time updates.

View File

@ -53,7 +53,7 @@ extern "C" {
#endif #endif
#ifndef ASSUME #ifndef ASSUME
# ifdef UNREACHABLE # ifdef UNREACHABLE
# define ASSUME(x) (LIKELY(!!(x)) ? (void)0 : UNREACHABLE) # define ASSUME(x) (RB_LIKELY(!!(x)) ? (void)0 : UNREACHABLE)
# else # else
# define ASSUME(x) ((void)(x)) # define ASSUME(x) ((void)(x))
# endif # endif
@ -64,11 +64,11 @@ extern "C" {
/* likely */ /* likely */
#if __GNUC__ >= 3 #if __GNUC__ >= 3
#define LIKELY(x) (__builtin_expect(!!(x), 1)) #define RB_LIKELY(x) (__builtin_expect(!!(x), 1))
#define UNLIKELY(x) (__builtin_expect(!!(x), 0)) #define RB_UNLIKELY(x) (__builtin_expect(!!(x), 0))
#else /* __GNUC__ >= 3 */ #else /* __GNUC__ >= 3 */
#define LIKELY(x) (x) #define RB_LIKELY(x) (x)
#define UNLIKELY(x) (x) #define RB_UNLIKELY(x) (x)
#endif /* __GNUC__ >= 3 */ #endif /* __GNUC__ >= 3 */
#ifdef __GNUC__ #ifdef __GNUC__
@ -1628,10 +1628,10 @@ rb_mul_size_overflow(size_t a, size_t b, size_t max, size_t *c)
{ {
#ifdef DSIZE_T #ifdef DSIZE_T
DSIZE_T c2 = (DSIZE_T)a * (DSIZE_T)b; DSIZE_T c2 = (DSIZE_T)a * (DSIZE_T)b;
if (UNLIKELY(c2 > max)) return 1; if (RB_UNLIKELY(c2 > max)) return 1;
*c = (size_t)c2; *c = (size_t)c2;
#else #else
if (b != 0 && UNLIKELY(a > max / b)) return 1; if (b != 0 && RB_UNLIKELY(a > max / b)) return 1;
*c = a * b; *c = a * b;
#endif #endif
return 0; return 0;
@ -1641,13 +1641,13 @@ rb_alloc_tmp_buffer2(volatile VALUE *store, long count, size_t elsize)
{ {
size_t cnt = (size_t)count; size_t cnt = (size_t)count;
if (elsize % sizeof(VALUE) == 0) { if (elsize % sizeof(VALUE) == 0) {
if (UNLIKELY(cnt > LONG_MAX / sizeof(VALUE))) { if (RB_UNLIKELY(cnt > LONG_MAX / sizeof(VALUE))) {
ruby_malloc_size_overflow(cnt, elsize); ruby_malloc_size_overflow(cnt, elsize);
} }
} }
else { else {
size_t size, max = LONG_MAX - sizeof(VALUE) + 1; size_t size, max = LONG_MAX - sizeof(VALUE) + 1;
if (UNLIKELY(rb_mul_size_overflow(count, elsize, max, &size))) { if (RB_UNLIKELY(rb_mul_size_overflow(count, elsize, max, &size))) {
ruby_malloc_size_overflow(cnt, elsize); ruby_malloc_size_overflow(cnt, elsize);
} }
cnt = (size + sizeof(VALUE) - 1) / sizeof(VALUE); cnt = (size + sizeof(VALUE) - 1) / sizeof(VALUE);

View File

@ -23,6 +23,9 @@ extern "C" {
#endif #endif
#endif #endif
#define LIKELY(x) RB_LIKELY(x)
#define UNLIKELY(x) RB_UNLIKELY(x)
#ifndef __has_attribute #ifndef __has_attribute
# define __has_attribute(x) 0 # define __has_attribute(x) 0
#endif #endif