summaryrefslogtreecommitdiff
path: root/internal.h
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@cookpad.com>2019-01-16 10:48:30 +0000
committerKoichi Sasada <ko1@atdot.net>2019-07-31 09:44:23 +0900
commitebd398ac5a4147a1e652d6943c39a29a62f12e66 (patch)
tree79dba6622c591db987f0a9c065fe37cd09a58e98 /internal.h
parent4afd8975242917d319cfb20c7ed635b979ad48d5 (diff)
remove RHash::iter_lev.
iter_lev is used to detect the hash is iterating or not. Usually, iter_lev should be very small number (1 or 2) so `int` is overkill. This patch introduce iter_lev in flags (7 bits, FL13 to FL19) and if iter_lev exceeds this range, save it in hidden attribute. We can get 1 word in RHash. We can't modify frozen objects. Therefore I added new internal API `rb_ivar_set_internal()` which allows us to set an attribute even if the target object is frozen if the name is hidden ivar (the name without `@` prefix).
Diffstat (limited to 'internal.h')
-rw-r--r--internal.h22
1 files changed, 14 insertions, 8 deletions
diff --git a/internal.h b/internal.h
index 0c6341aad5..0c148bfe3b 100644
--- a/internal.h
+++ b/internal.h
@@ -815,13 +815,22 @@ struct RComplex {
#define RCOMPLEX_SET_IMAG(cmp, i) RB_OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->imag,(i))
enum ruby_rhash_flags {
- RHASH_ST_TABLE_FLAG = FL_USER3,
+ RHASH_ST_TABLE_FLAG = FL_USER3, /* FL 3 */
RHASH_AR_TABLE_MAX_SIZE = 8,
- RHASH_AR_TABLE_SIZE_MASK = (FL_USER4|FL_USER5|FL_USER6|FL_USER7),
+ RHASH_AR_TABLE_SIZE_MASK = (FL_USER4|FL_USER5|FL_USER6|FL_USER7), /* FL 4..7 */
RHASH_AR_TABLE_SIZE_SHIFT = (FL_USHIFT+4),
- RHASH_AR_TABLE_BOUND_MASK = (FL_USER8|FL_USER9|FL_USER10|FL_USER11),
+ RHASH_AR_TABLE_BOUND_MASK = (FL_USER8|FL_USER9|FL_USER10|FL_USER11), /* FL 8..11 */
RHASH_AR_TABLE_BOUND_SHIFT = (FL_USHIFT+8),
+#if USE_TRANSIENT_HEAP
+ RHASH_TRANSIENT_FLAG = FL_USER12, /* FL 12 */
+#endif
+
+ RHASH_LEV_MASK = (FL_USER13 | FL_USER14 | FL_USER15 | /* FL 13..19 */
+ FL_USER16 | FL_USER17 | FL_USER18 | FL_USER19),
+ RHASH_LEV_SHIFT = (FL_USHIFT + 13),
+ RHASH_LEV_MAX = 127, /* 7 bits */
+
RHASH_ENUM_END
};
@@ -856,7 +865,6 @@ void rb_hash_st_table_set(VALUE hash, st_table *st);
#define RHASH_AR_TABLE_BOUND_SHIFT RHASH_AR_TABLE_BOUND_SHIFT
#if USE_TRANSIENT_HEAP
-#define RHASH_TRANSIENT_FLAG FL_USER14
#define RHASH_TRANSIENT_P(hash) FL_TEST_RAW((hash), RHASH_TRANSIENT_FLAG)
#define RHASH_SET_TRANSIENT_FLAG(h) FL_SET_RAW(h, RHASH_TRANSIENT_FLAG)
#define RHASH_UNSET_TRANSIENT_FLAG(h) FL_UNSET_RAW(h, RHASH_TRANSIENT_FLAG)
@@ -872,16 +880,14 @@ struct RHash {
st_table *st;
struct ar_table_struct *ar; /* possibly 0 */
} as;
- int iter_lev;
const VALUE ifnone;
+ const VALUE reserved;
};
-#ifdef RHASH_ITER_LEV
-# undef RHASH_ITER_LEV
+#ifdef RHASH_IFNONE
# undef RHASH_IFNONE
# undef RHASH_SIZE
-# define RHASH_ITER_LEV(h) (RHASH(h)->iter_lev)
# define RHASH_IFNONE(h) (RHASH(h)->ifnone)
# define RHASH_SIZE(h) (RHASH_AR_TABLE_P(h) ? RHASH_AR_TABLE_SIZE_RAW(h) : RHASH_ST_SIZE(h))
#endif /* #ifdef RHASH_ITER_LEV */