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

ruby-changes:45922

From: normal <ko1@a...>
Date: Fri, 17 Mar 2017 09:55:50 +0900 (JST)
Subject: [ruby-changes:45922] normal:r57995 (trunk): deduplicate "/", ":" and "\n" strings

normal	2017-03-17 09:55:45 +0900 (Fri, 17 Mar 2017)

  New Revision: 57995

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

  Log:
    deduplicate "/", ":" and "\n" strings
    
    "/" and ":" are always statically registered in symbol.c (Init_op_tbl),
    and "\n" is a commonly seen in source code.
    
    * file.c (Init_File): fstring on File::SEPARATOR and File::PATH_SEPARATOR
    * io.c (Init_IO): fstring on rb_default_rs ("\n")

  Modified files:
    trunk/file.c
    trunk/io.c
Index: file.c
===================================================================
--- file.c	(revision 57994)
+++ file.c	(revision 57995)
@@ -6013,7 +6013,7 @@ Init_File(void) https://github.com/ruby/ruby/blob/trunk/file.c#L6013
     rb_define_singleton_method(rb_cFile, "extname", rb_file_s_extname, 1);
     rb_define_singleton_method(rb_cFile, "path", rb_file_s_path, 1);
 
-    separator = rb_obj_freeze(rb_usascii_str_new2("/"));
+    separator = rb_fstring_cstr("/");
     /* separates directory parts in path */
     rb_define_const(rb_cFile, "Separator", separator);
     rb_define_const(rb_cFile, "SEPARATOR", separator);
@@ -6027,7 +6027,7 @@ Init_File(void) https://github.com/ruby/ruby/blob/trunk/file.c#L6027
     rb_define_const(rb_cFile, "ALT_SEPARATOR", Qnil);
 #endif
     /* path list separator */
-    rb_define_const(rb_cFile, "PATH_SEPARATOR", rb_obj_freeze(rb_str_new2(PATH_SEP)));
+    rb_define_const(rb_cFile, "PATH_SEPARATOR", rb_fstring_cstr(PATH_SEP));
 
     rb_define_method(rb_cIO, "stat",  rb_io_stat, 0); /* this is IO's method */
     rb_define_method(rb_cFile, "lstat",  rb_file_lstat, 0);
Index: io.c
===================================================================
--- io.c	(revision 57994)
+++ io.c	(revision 57995)
@@ -12413,10 +12413,10 @@ Init_IO(void) https://github.com/ruby/ruby/blob/trunk/io.c#L12413
     rb_output_fs = Qnil;
     rb_define_hooked_variable("$,", &rb_output_fs, 0, rb_str_setter);
 
-    rb_rs = rb_default_rs = rb_usascii_str_new2("\n");
+    rb_default_rs = rb_fstring_cstr("\n"); /* avoid modifying RS_default */
     rb_gc_register_mark_object(rb_default_rs);
+    rb_rs = rb_default_rs;
     rb_output_rs = Qnil;
-    OBJ_FREEZE(rb_default_rs);	/* avoid modifying RS_default */
     rb_define_hooked_variable("$/", &rb_rs, 0, rb_str_setter);
     rb_define_hooked_variable("$-0", &rb_rs, 0, rb_str_setter);
     rb_define_hooked_variable("$\\", &rb_output_rs, 0, rb_str_setter);

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

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