Count Enumerable#count with an unsigned member of MEMO

Only imemo_count_up and imemo_count_value treat the count as unsigned, so keep cnt as rb_len_t for the other users of MEMO and give them their own member.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hiroshi SHIBATAandClaude Opus 5.5 committed 2026-10-10 16:45:25 +09:00
1 parent 3af4f5f695
commit cedc07cc8d
2 files changed
+4 -3
Notes: git 2026-10-10 07:46:22 +00:00

No files matched your search

+2 -2
View File
@@ -222,7 +222,7 @@ imemo_count_up(struct MEMO *memo)
RUBY_ASSERT(RB_TYPE_P(memo->u3.value, T_BIGNUM));
MEMO_V3_SET(memo, rb_int_succ(memo->u3.value));
}
else if (++memo->u3.cnt == 0) {
else if (++memo->u3.ucnt == 0) {
/* overflow */
MEMO_V3_SET(memo, rb_int_succ(ULEN2NUM(RB_ULEN_MAX)));
}
@@ -236,7 +236,7 @@ imemo_count_value(struct MEMO *memo)
return memo->u3.value;
}
else {
return ULEN2NUM(memo->u3.cnt);
return ULEN2NUM(memo->u3.ucnt);
}
}
+2 -1
View File
@@ -108,7 +108,7 @@ struct rb_imemo_cdhash {
};
/* Set on imemo_memo when u3 holds a VALUE that GC must mark.
* When unset, u3 is a non-VALUE (cnt/state). */
* When unset, u3 is a non-VALUE (cnt/ucnt/state). */
#define MEMO_U3_IS_VALUE IMEMO_FL_USER0
/*! MEMO
@@ -121,6 +121,7 @@ struct MEMO {
const VALUE v2;
union {
rb_len_t cnt;
rb_ulen_t ucnt;
long state;
const VALUE value;
} u3;