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

ruby-changes:41624

From: nobu <ko1@a...>
Date: Sun, 31 Jan 2016 12:10:14 +0900 (JST)
Subject: [ruby-changes:41624] nobu:r53698 (trunk): io.c: rb_io_open_generic

nobu	2016-01-31 12:11:14 +0900 (Sun, 31 Jan 2016)

  New Revision: 53698

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

  Log:
    io.c: rb_io_open_generic
    
    * io.c (rb_io_open_generic): split from rb_io_open without
      argument conversions.
    
    * io.c (rb_io_s_binread): get rid of unnecessary object creation
      and conversion.

  Modified files:
    trunk/io.c
Index: io.c
===================================================================
--- io.c	(revision 53697)
+++ io.c	(revision 53698)
@@ -6578,23 +6578,31 @@ rb_f_open(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/io.c#L6578
     return rb_io_s_open(argc, argv, rb_cFile);
 }
 
+static VALUE rb_io_open_generic(VALUE, int, int, const convconfig_t *, mode_t);
+
 static VALUE
 rb_io_open(VALUE filename, VALUE vmode, VALUE vperm, VALUE opt)
 {
-    VALUE cmd;
     int oflags, fmode;
     convconfig_t convconfig;
     mode_t perm;
 
     rb_io_extract_modeenc(&vmode, &vperm, opt, &oflags, &fmode, &convconfig);
     perm = NIL_P(vperm) ? 0666 :  NUM2MODET(vperm);
+    return rb_io_open_generic(filename, oflags, fmode, &convconfig, perm);
+}
 
+static VALUE
+rb_io_open_generic(VALUE filename, int oflags, int fmode,
+		   const convconfig_t *convconfig, mode_t perm)
+{
+    VALUE cmd;
     if (!NIL_P(cmd = check_pipe_command(filename))) {
-	return pipe_open_s(cmd, rb_io_oflags_modestr(oflags), fmode, &convconfig);
+	return pipe_open_s(cmd, rb_io_oflags_modestr(oflags), fmode, convconfig);
     }
     else {
         return rb_file_open_generic(io_alloc(rb_cFile), filename,
-                oflags, fmode, &convconfig, perm);
+				    oflags, fmode, convconfig, perm);
     }
 }
 
@@ -9899,10 +9907,19 @@ rb_io_s_binread(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/io.c#L9907
 {
     VALUE offset;
     struct foreach_arg arg;
+    enum {
+	fmode = FMODE_READABLE|FMODE_BINMODE,
+	oflags = O_RDONLY
+#ifdef O_BINARY
+		|O_BINARY
+#endif
+    };
+    convconfig_t convconfig = {NULL, NULL, 0, Qnil};
 
     rb_scan_args(argc, argv, "12", NULL, NULL, &offset);
     FilePathValue(argv[0]);
-    arg.io = rb_io_open(argv[0], rb_str_new_cstr("rb:ASCII-8BIT"), Qnil, Qnil);
+    convconfig.enc = rb_ascii8bit_encoding();
+    arg.io = rb_io_open_generic(argv[0], oflags, fmode, &convconfig, 0);
     if (NIL_P(arg.io)) return Qnil;
     arg.argv = argv+1;
     arg.argc = (argc > 1) ? 1 : 0;

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

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