ruby-changes:4596
From: ko1@a...
Date: Sun, 20 Apr 2008 13:59:22 +0900 (JST)
Subject: [ruby-changes:4596] akr - Ruby:r16090 (trunk): * io.c (copy_stream_fallback): write directly (bypassing write method)
akr 2008-04-20 13:59:04 +0900 (Sun, 20 Apr 2008) New Revision: 16090 Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Log: * io.c (copy_stream_fallback): write directly (bypassing write method) if possible. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_io.rb?r1=16090&r2=16089&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16090&r2=16089&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=16090&r2=16089&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 16089) +++ ChangeLog (revision 16090) @@ -1,8 +1,13 @@ -Sun Apr 20 12:49:03 2008 Tanaka Akira <akr@f...> +Sun Apr 20 13:55:37 2008 Tanaka Akira <akr@f...> - * io.c (copy_stream_fallback): read directly (bypassing readpartial) + * io.c (copy_stream_fallback): write directly (bypassing write method) if possible. +Sun Apr 20 12:49:03 2008 Tanaka Akira <akr@f...> + + * io.c (copy_stream_fallback): read directly (bypassing readpartial + method) if possible. + Sun Apr 20 04:45:13 2008 Tanaka Akira <akr@f...> * io.c (copy_stream_body): use readpartial and write method for Index: io.c =================================================================== --- io.c (revision 16089) +++ io.c (revision 16090) @@ -6579,7 +6579,7 @@ while (1) { long numwrote; - long l = buflen < rest ? buflen : rest; + long l; if (stp->copy_length == (off_t)-1) { l = buflen; } @@ -6604,9 +6604,18 @@ if (off != (off_t)-1) off += ss; } - n = rb_io_write(stp->dst, buf); - numwrote = NUM2LONG(n); - stp->total += numwrote; + if (stp->dst_fd == -1) { + n = rb_io_write(stp->dst, buf); + numwrote = NUM2LONG(n); + stp->total += numwrote; + } + else { + ssize_t ss; + numwrote = RSTRING_LEN(buf); + ss = copy_stream_write(stp, RSTRING_PTR(buf), numwrote); + if (ss == -1) + return Qnil; + } rest -= numwrote; } Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 16089) +++ test/ruby/test_io.rb (revision 16090) @@ -424,25 +424,30 @@ } end - def test_copy_stream_non_io + def test_copy_stream_fname_to_strio mkcdtmpdir {|d| - # filename to StringIO File.open("foo", "w") {|f| f << "abcd" } src = "foo" dst = StringIO.new ret = IO.copy_stream(src, dst, 3) assert_equal(3, ret) assert_equal("abc", dst.string) + } + end + def test_copy_stream_strio_to_fname + mkcdtmpdir {|d| # StringIO to filename src = StringIO.new("abcd") - ret = File.open("fooo", "w") {|dst| - IO.copy_stream(src, dst, 3) - } + ret = IO.copy_stream(src, "fooo", 3) assert_equal(3, ret) - assert_equal("abc", dst.string) + assert_equal("abc", File.read("fooo")) assert_equal(3, src.pos) + } + end + def test_copy_stream_io_to_strio + mkcdtmpdir {|d| # IO to StringIO File.open("bar", "w") {|f| f << "abcd" } File.open("bar") {|src| @@ -452,7 +457,11 @@ assert_equal("abc", dst.string) assert_equal(3, src.pos) } + } + end + def test_copy_stream_strio_to_io + mkcdtmpdir {|d| # StringIO to IO src = StringIO.new("abcd") ret = File.open("baz", "w") {|dst| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/