aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-25 05:44:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-25 05:44:38 +0000
commit908341aabb97dcbd43364c3f27a1b37b5dc140dc (patch)
tree08029047a84a89d290ac70b5461ae5b620d8390a /io.c
parentc22d62485fd20fbd4f79b026b7a03314caa0f81c (diff)
downloadruby-908341aabb97dcbd43364c3f27a1b37b5dc140dc.tar.gz
io.c: write a newline together
* io.c (rb_io_puts): write a newline together at once for each argument. based on the patch by rohitpaulk (Rohit Kuruvilla) at [ruby-core:83508]. [Feature #14042] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/io.c b/io.c
index 818399271e..03cd40e7e8 100644
--- a/io.c
+++ b/io.c
@@ -1686,6 +1686,16 @@ rb_io_write(VALUE io, VALUE str)
return rb_funcallv(io, id_write, 1, &str);
}
+static VALUE
+rb_io_writev(VALUE io, int argc, VALUE *argv)
+{
+ if (argc > 1 && rb_obj_method_arity(io, id_write) == 1) {
+ do rb_io_write(io, *argv++); while (--argc);
+ return argv[0]; /* unused right now */
+ }
+ return rb_funcallv(io, id_write, argc, argv);
+}
+
/*
* call-seq:
* ios << obj -> ios
@@ -7572,8 +7582,8 @@ io_puts_ary(VALUE ary, VALUE out, int recur)
VALUE
rb_io_puts(int argc, const VALUE *argv, VALUE out)
{
- int i;
- VALUE line;
+ int i, n;
+ VALUE line, args[2];
/* if no argument given, print newline. */
if (argc == 0) {
@@ -7590,11 +7600,13 @@ rb_io_puts(int argc, const VALUE *argv, VALUE out)
}
line = rb_obj_as_string(argv[i]);
string:
- rb_io_write(out, line);
+ n = 0;
+ args[n++] = line;
if (RSTRING_LEN(line) == 0 ||
!rb_str_end_with_asciichar(line, '\n')) {
- rb_io_write(out, rb_default_rs);
+ args[n++] = rb_default_rs;
}
+ rb_io_writev(out, n, args);
}
return Qnil;