summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authorKouhei Yanagita <[email protected]>2023-10-05 00:19:55 +0900
committer<[email protected]>2023-10-05 00:19:55 +0900
commit6ae2996e291750bab4ff59a06ba11c8d6bbe5aaa ()
tree764f5d10e70c59757ef108f3e1dc741d30d7042e /range.c
parente0c66b47499e9372fdf86610f0da65efb6f60af9 (diff)
Optimize `Range#count` by using `range_size` if possible
-rw-r--r--range.c23
1 files changed, 16 insertions, 7 deletions
@@ -607,6 +607,10 @@ double_as_int64(double d)
static int
is_integer_p(VALUE v)
{
ID id_integer_p;
VALUE is_int;
CONST_ID(id_integer_p, "integer?");
@@ -2166,17 +2170,22 @@ range_count(int argc, VALUE *argv, VALUE range)
* Infinity. Just let it loop. */
return rb_call_super(argc, argv);
}
- else if (NIL_P(RANGE_END(range))) {
- /* We are confident that the answer is Infinity. */
- return DBL2NUM(HUGE_VAL);
- }
- else if (NIL_P(RANGE_BEG(range))) {
/* We are confident that the answer is Infinity. */
return DBL2NUM(HUGE_VAL);
}
- else {
- return rb_call_super(argc, argv);
}
}
static bool