* [PATCH] compile.c: apply opt_str_freeze to String#-@ (uminus)
@ 2017-03-08 21:23 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2017-03-08 21:23 UTC (permalink / raw)
To: spew
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2017-03-08 21:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-08 21:23 [PATCH] compile.c: apply opt_str_freeze to String#-@ (uminus) Eric Wong
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).