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

ruby-changes:54615

From: nobu <ko1@a...>
Date: Tue, 15 Jan 2019 21:05:53 +0900 (JST)
Subject: [ruby-changes:54615] nobu:r66830 (trunk): Use `&` instead of `modulo`

nobu	2019-01-15 21:05:46 +0900 (Tue, 15 Jan 2019)

  New Revision: 66830

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

  Log:
    Use `&` instead of `modulo`

  Modified files:
    trunk/ext/stringio/stringio.c
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 66829)
+++ string.c	(revision 66830)
@@ -5421,7 +5421,7 @@ rb_str_setbyte(VALUE str, VALUE index, V https://github.com/ruby/ruby/blob/trunk/string.c#L5421
         pos += len;
 
     VALUE v = rb_to_int(value);
-    VALUE w = rb_int_modulo(v, INT2FIX(256));
+    VALUE w = rb_int_and(v, INT2FIX(0xff));
     unsigned char byte = NUM2INT(w) & 0xFF;
 
     if (!str_independent(str))
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 66829)
+++ ext/stringio/stringio.c	(revision 66830)
@@ -810,11 +810,11 @@ strio_ungetbyte(VALUE self, VALUE c) https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L810
         return Qnil;
       case T_FIXNUM:
       case T_BIGNUM: ;
-        /* rb_int_modulo() not visible from exts */
-        VALUE v = rb_funcall(c, rb_intern("modulo"), 1, INT2FIX(256));
-        unsigned char cc = NUM2INT(v) & 0xFF;
-        c = rb_str_new((const char *)&cc, 1);
-        break;
+        /* rb_int_and() not visible from exts */
+        VALUE v = rb_funcall(c, '&', 1, INT2FIX(0xff));
+        const char cc = NUM2INT(v) & 0xFF;
+        strio_unget_bytes(ptr, &cc, 1);
+        return Qnil;
       default:
         SafeStringValue(c);
     }

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

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