dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] compile.c: apply opt_str_freeze to String#-@ (uminus)
Date: Wed,  8 Mar 2017 21:23:30 +0000	[thread overview]
Message-ID: <20170308212330.8145-1-e@80x24.org> (raw)

The same optimization used for "literal string".freeze
can easily apply to uminus without introducing any
compatibility problems.
---
 bootstraptest/test_insns.rb | 1 +
 compile.c                   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/bootstraptest/test_insns.rb b/bootstraptest/test_insns.rb
index 2001e2c0ef..3a6e677885 100644
--- a/bootstraptest/test_insns.rb
+++ b/bootstraptest/test_insns.rb
@@ -178,6 +178,7 @@ def x
   },
 
   [ 'opt_str_freeze', %q{ 'true'.freeze }, ],
+  [ 'opt_str_freeze', %q{ -'true' }, ],
   [ 'opt_str_freeze', <<~'},', ], # {
     class String
       def freeze
diff --git a/compile.c b/compile.c
index 835fa41414..154021dcba 100644
--- a/compile.c
+++ b/compile.c
@@ -5188,7 +5188,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int poppe
 	 *   "literal".freeze -> opt_str_freeze("literal")
 	 */
 	if (node->nd_recv && nd_type(node->nd_recv) == NODE_STR &&
-	    node->nd_mid == idFreeze && node->nd_args == NULL &&
+	    (node->nd_mid == idFreeze || node->nd_mid == idUMinus) &&
+	    node->nd_args == NULL &&
 	    ISEQ_COMPILE_DATA(iseq)->current_block == NULL &&
 	    ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
 	    VALUE str = rb_fstring(node->nd_recv->nd_lit);
-- 
EW


                 reply	other threads:[~2017-03-08 21:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20170308212330.8145-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).