1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Introduce BIGNUM_EMBED_P to check BIGNUM_EMBED_FLAG (#2802)

* bignum.h: Add BIGNUM_EMBED_P

* bignum.c: Use macros for handling BIGNUM_EMBED_FLAG
This commit is contained in:
Kenta Murata 2019-12-31 22:48:23 +09:00 committed by GitHub
parent 4ce28b58cb
commit e082f41611
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2019-12-31 22:48:53 +09:00
Merged-By: mrkn <mrkn@ruby-lang.org>
3 changed files with 17 additions and 9 deletions

View file

@ -139,6 +139,7 @@ static inline void BIGNUM_NEGATE(VALUE b);
static inline size_t BIGNUM_LEN(VALUE b);
static inline BDIGIT *BIGNUM_DIGITS(VALUE b);
static inline int BIGNUM_LENINT(VALUE b);
static inline bool BIGNUM_EMBED_P(VALUE b);
RUBY_SYMBOL_EXPORT_BEGIN
/* bignum.c (export) */
@ -207,7 +208,7 @@ BIGNUM_NEGATE(VALUE b)
static inline size_t
BIGNUM_LEN(VALUE b)
{
if (! FL_TEST_RAW(b, BIGNUM_EMBED_FLAG)) {
if (! BIGNUM_EMBED_P(b)) {
return RBIGNUM(b)->as.heap.len;
}
else {
@ -228,11 +229,18 @@ BIGNUM_LENINT(VALUE b)
static inline BDIGIT *
BIGNUM_DIGITS(VALUE b)
{
if (FL_TEST_RAW(b, BIGNUM_EMBED_FLAG)) {
if (BIGNUM_EMBED_P(b)) {
return RBIGNUM(b)->as.ary;
}
else {
return RBIGNUM(b)->as.heap.digits;
}
}
static inline bool
BIGNUM_EMBED_P(VALUE b)
{
return FL_TEST_RAW(b, BIGNUM_EMBED_FLAG);
}
#endif /* INTERNAL_BIGNUM_H */