Permalink
Browse files

Hash#[]= will not duplicate already frozen string key.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

key = "foo".freeze
h = {}
h[key] = 42

assert_equal( h.keys[0].object_id, key.object_id )

puts :ok
}}}

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@5295 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 9ed4545 commit 39a910469450c22cc06e5029959c9c5def7ca693 @Watson1978 Watson1978 committed Mar 23, 2011
Showing with 1 addition and 1 deletion.
  1. +1 −1 hash.c
View
2 hash.c
@@ -964,7 +964,7 @@ VALUE
rhash_aset(VALUE hash, SEL sel, VALUE key, VALUE val)
{
rhash_modify(hash);
- if (TYPE(key) == T_STRING) {
+ if (TYPE(key) == T_STRING && !OBJ_FROZEN(key)) {
key = rb_str_dup(key);
OBJ_FREEZE(key);
}

0 comments on commit 39a9104

Please sign in to comment.