From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 1/3] deduplicate "/", ":" and "\n" strings
Date: Thu, 16 Mar 2017 23:57:07 +0000 [thread overview]
Message-ID: <20170316235709.20071-1-e@80x24.org> (raw)
"/" 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")
---
file.c | 4 ++--
io.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/file.c b/file.c
index 3f1212d91c..8bca84283d 100644
--- a/file.c
+++ b/file.c
@@ -6013,7 +6013,7 @@ Init_File(void)
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)
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);
diff --git a/io.c b/io.c
index 3c2a0a46c4..29b3f525bb 100644
--- a/io.c
+++ b/io.c
@@ -12413,10 +12413,10 @@ Init_IO(void)
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);
--
EW
next reply other threads:[~2017-03-16 23:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-16 23:57 Eric Wong [this message]
2017-03-16 23:57 ` [PATCH 2/3] deduplicate File::NULL string Eric Wong
2017-03-16 23:57 ` [PATCH 3/3] deduplicate static rb_str_format format strings Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170316235709.20071-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).