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

ruby-changes:32392

From: glass <ko1@a...>
Date: Tue, 31 Dec 2013 21:25:23 +0900 (JST)
Subject: [ruby-changes:32392] glass:r44471 (trunk): * io.c (io_fwrite): allocate frozen str only when str is not converted.

glass	2013-12-31 21:25:16 +0900 (Tue, 31 Dec 2013)

  New Revision: 44471

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44471

  Log:
    * io.c (io_fwrite): allocate frozen str only when str is not converted.

  Modified files:
    trunk/ChangeLog
    trunk/io.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44470)
+++ ChangeLog	(revision 44471)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec 31 21:02:27 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* io.c (io_fwrite): allocate frozen str only when str is not converted.
+
 Tue Dec 31 15:44:48 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/mkmf.rb (RbConfig): expand RUBY_SO_NAME for extensions
Index: io.c
===================================================================
--- io.c	(revision 44470)
+++ io.c	(revision 44471)
@@ -1291,7 +1291,7 @@ io_binwrite(VALUE str, const char *ptr, https://github.com/ruby/ruby/blob/trunk/io.c#L1291
 # define MODE_BTMODE(a,b,c) ((fmode & FMODE_BINMODE) ? (b) : \
                              (fmode & FMODE_TEXTMODE) ? (c) : (a))
 static VALUE
-do_writeconv(VALUE str, rb_io_t *fptr)
+do_writeconv(VALUE str, rb_io_t *fptr, int *converted)
 {
     if (NEED_WRITECONV(fptr)) {
         VALUE common_encoding = Qnil;
@@ -1319,10 +1319,12 @@ do_writeconv(VALUE str, rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L1319
         if (!NIL_P(common_encoding)) {
             str = rb_str_encode(str, common_encoding,
                 fptr->writeconv_pre_ecflags, fptr->writeconv_pre_ecopts);
+	    *converted = 1;
         }
 
         if (fptr->writeconv) {
             str = rb_econv_str_convert(fptr->writeconv, str, ECONV_PARTIAL_INPUT);
+	    *converted = 1;
         }
     }
 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
@@ -1348,13 +1350,15 @@ do_writeconv(VALUE str, rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L1350
 static long
 io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
 {
+    int converted = 0;
 #ifdef _WIN32
     if (fptr->mode & FMODE_TTY) {
 	long len = rb_w32_write_console(str, fptr->fd);
 	if (len > 0) return len;
     }
 #endif
-    str = do_writeconv(str, fptr);
+    str = do_writeconv(str, fptr, &converted);
+    if (!converted) str = rb_str_new_frozen(str);
     return io_binwrite(str, RSTRING_PTR(str), RSTRING_LEN(str),
 		       fptr, nosync);
 }
@@ -1386,8 +1390,6 @@ io_write(VALUE io, VALUE str, int nosync https://github.com/ruby/ruby/blob/trunk/io.c#L1390
     io = tmp;
     if (RSTRING_LEN(str) == 0) return INT2FIX(0);
 
-    str = rb_str_new_frozen(str);
-
     GetOpenFile(io, fptr);
     rb_io_check_writable(fptr);
 

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

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