[前][次][番号順一覧][スレッド一覧]

ruby-changes:43357

From: nobu <ko1@a...>
Date: Fri, 17 Jun 2016 17:45:13 +0900 (JST)
Subject: [ruby-changes:43357] nobu:r55430 (trunk): Unnecessary checks

nobu	2016-06-17 17:45:05 +0900 (Fri, 17 Jun 2016)

  New Revision: 55430

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55430

  Log:
    Unnecessary checks
    
    * ext/bigdecimal/bigdecimal.c: FIX2INT and FIX2UINT imply the
      check for Fixnum.
    
    * ext/zlib/zlib.c: ditto.

  Modified files:
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/ext/zlib/zlib.c
Index: ext/zlib/zlib.c
===================================================================
--- ext/zlib/zlib.c	(revision 55429)
+++ ext/zlib/zlib.c	(revision 55430)
@@ -1363,7 +1363,6 @@ rb_zstream_set_avail_out(VALUE obj, VALU https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1363
 {
     struct zstream *z = get_zstream(obj);
 
-    Check_Type(size, T_FIXNUM);
     zstream_expand_buffer_into(z, FIX2INT(size));
     return size;
 }
@@ -1449,7 +1448,7 @@ rb_zstream_closed_p(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1448
 
 #define FIXNUMARG(val, ifnil) \
     (NIL_P((val)) ? (ifnil) \
-    : ((void)Check_Type((val), T_FIXNUM), FIX2INT((val))))
+    : (FIX2INT((val))))
 
 #define ARG_LEVEL(val)     FIXNUMARG((val), Z_DEFAULT_COMPRESSION)
 #define ARG_WBITS(val)     FIXNUMARG((val), MAX_WBITS)
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 55429)
+++ ext/bigdecimal/bigdecimal.c	(revision 55430)
@@ -468,7 +468,6 @@ check_rounding_mode(VALUE const v) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L468
 	break;
     }
 
-    Check_Type(v, T_FIXNUM);
     sw = (unsigned short)FIX2UINT(v);
     if (!VpIsRoundMode(sw)) {
 	rb_raise(rb_eArgError, "invalid rounding mode");
@@ -522,7 +521,6 @@ BigDecimal_mode(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L521
     unsigned long f,fo;
 
     rb_scan_args(argc, argv, "11", &which, &val);
-    Check_Type(which, T_FIXNUM);
     f = (unsigned long)FIX2INT(which);
 
     if (f & VP_EXCEPTION_ALL) {
@@ -593,7 +591,6 @@ static SIGNED_VALUE https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L591
 GetPositiveInt(VALUE v)
 {
     SIGNED_VALUE n;
-    Check_Type(v, T_FIXNUM);
     n = FIX2INT(v);
     if (n < 0) {
 	rb_raise(rb_eArgError, "argument must be positive");
@@ -1723,11 +1720,9 @@ BigDecimal_round(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1720
 	iLoc = 0;
 	break;
       case 1:
-	Check_Type(vLoc, T_FIXNUM);
 	iLoc = FIX2INT(vLoc);
 	break;
       case 2:
-	Check_Type(vLoc, T_FIXNUM);
 	iLoc = FIX2INT(vLoc);
 	sw = check_rounding_mode(vRound);
 	break;
@@ -1779,7 +1774,6 @@ BigDecimal_truncate(int argc, VALUE *arg https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1774
 	iLoc = 0;
     }
     else {
-	Check_Type(vLoc, T_FIXNUM);
 	iLoc = FIX2INT(vLoc);
     }
 
@@ -1840,7 +1834,6 @@ BigDecimal_floor(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1834
 	iLoc = 0;
     }
     else {
-	Check_Type(vLoc, T_FIXNUM);
 	iLoc = FIX2INT(vLoc);
     }
 
@@ -1887,7 +1880,6 @@ BigDecimal_ceil(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1880
     if (rb_scan_args(argc, argv, "01", &vLoc) == 0) {
 	iLoc = 0;
     } else {
-	Check_Type(vLoc, T_FIXNUM);
 	iLoc = FIX2INT(vLoc);
     }
 
@@ -2631,7 +2623,6 @@ BigDecimal_limit(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2623
     if (rb_scan_args(argc, argv, "01", &nFig) == 1) {
 	int nf;
 	if (NIL_P(nFig)) return nCur;
-	Check_Type(nFig, T_FIXNUM);
 	nf = FIX2INT(nFig);
 	if (nf < 0) {
 	    rb_raise(rb_eArgError, "argument must be positive");

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]