Skip to content

Commit

Permalink
Hash#[]= will not duplicate already frozen string key.
Browse files Browse the repository at this point in the history
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
Watson1978 committed Mar 23, 2011
1 parent 9ed4545 commit 39a9104
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion hash.c
Expand Up @@ -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);
}
Expand Down

0 comments on commit 39a9104

Please sign in to comment.