Skip to content

Commit

Permalink
compile.c: apply opt_str_freeze to String#-@ (uminus)
Browse files Browse the repository at this point in the history
The same optimization used for "literal string".freeze
can easily apply to uminus without introducing any
compatibility problems.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
normal committed Mar 10, 2017
1 parent c51de81 commit 568f8ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions bootstraptest/test_insns.rb
Expand Up @@ -178,6 +178,7 @@ def x
},

[ 'opt_str_freeze', %q{ 'true'.freeze }, ],
[ 'opt_str_freeze', %q{ -'true' }, ],
[ 'opt_str_freeze', <<~'},', ], # {
class String
def freeze
Expand Down
3 changes: 2 additions & 1 deletion compile.c
Expand Up @@ -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);
Expand Down

0 comments on commit 568f8ad

Please sign in to comment.