summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-06 07:49:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-06 07:49:24 +0000
commit98e65d9d921ec810bbae2233b80e865e76dd8502 (patch)
tree16ce055f3f2dfcedef55c4649e5eb3d7bf707040 /rational.c
parent0cd28199e50039e9425f10b880c436d3ecacde0b (diff)
Prefer rb_check_arity when 0 or 1 arguments
Especially over checking argc then calling rb_scan_args just to raise an ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/rational.c b/rational.c
index b320ed5..076d427 100644
--- a/rational.c
+++ b/rational.c
@@ -1385,10 +1385,10 @@ f_round_common(int argc, VALUE *argv, VALUE self, VALUE (*func)(VALUE))
{
VALUE n, b, s;
- if (argc == 0)
+ if (rb_check_arity(argc, 0, 1) == 0)
return (*func)(self);
- rb_scan_args(argc, argv, "01", &n);
+ n = argv[0];
if (!k_integer_p(n))
rb_raise(rb_eTypeError, "not an integer");
@@ -1711,14 +1711,13 @@ nurat_rationalize(int argc, VALUE *argv, VALUE self)
{
VALUE e, a, b, p, q;
- if (argc == 0)
+ if (rb_check_arity(argc, 0, 1) == 0)
return self;
if (nurat_negative_p(self))
return rb_rational_uminus(nurat_rationalize(argc, argv, rb_rational_uminus(self)));
- rb_scan_args(argc, argv, "01", &e);
- e = f_abs(e);
+ e = f_abs(argv[0]);
a = f_sub(self, e);
b = f_add(self, e);
@@ -2283,16 +2282,13 @@ rb_flt_rationalize(VALUE flt)
static VALUE
float_rationalize(int argc, VALUE *argv, VALUE self)
{
- VALUE e;
double d = RFLOAT_VALUE(self);
if (d < 0.0)
return rb_rational_uminus(float_rationalize(argc, argv, DBL2NUM(-d)));
- rb_scan_args(argc, argv, "01", &e);
-
- if (argc != 0) {
- return rb_flt_rationalize_with_prec(self, e);
+ if (rb_check_arity(argc, 0, 1)) {
+ return rb_flt_rationalize_with_prec(self, argv[0]);
}
else {
return rb_flt_rationalize(self);