Created
January 30, 2011 23:49
-
-
Save kronos/803436 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 49bdb23d6f71f9afb6c2efafcc48a8e1c4e4bc28 Mon Sep 17 00:00:00 2001 | |
From: Ivan Samsonov <[email protected]> | |
Date: Mon, 31 Jan 2011 02:44:42 +0300 | |
Subject: [PATCH 1/2] Enhance spec for using Hash#[]= with already frozen keys. | |
--- | |
spec/ruby/core/hash/shared/store.rb | 7 +++++++ | |
1 files changed, 7 insertions(+), 0 deletions(-) | |
diff --git a/spec/ruby/core/hash/shared/store.rb b/spec/ruby/core/hash/shared/store.rb | |
index 1362355..d89ddb5 100644 | |
--- a/spec/ruby/core/hash/shared/store.rb | |
+++ b/spec/ruby/core/hash/shared/store.rb | |
@@ -37,6 +37,13 @@ describe :hash_store, :shared => true do | |
h.keys[0].frozen?.should == true | |
end | |
+ it "doesn't duplicate and freeze already frozen string keys" do | |
+ key = "foo".freeze | |
+ h = new_hash | |
+ h.send(@method, key, 0) | |
+ h.keys[0].should equal(key) | |
+ end | |
+ | |
ruby_version_is ""..."1.9" do | |
it "raises a TypeError if called on a frozen instance" do | |
lambda { HashSpecs.frozen_hash.send(@method, 1, 2) }.should raise_error(TypeError) | |
-- | |
1.7.3.2 | |
From b29965ff66df1fe42e023d9dc97e77b34874cc96 Mon Sep 17 00:00:00 2001 | |
From: Ivan Samsonov <[email protected]> | |
Date: Mon, 31 Jan 2011 02:46:25 +0300 | |
Subject: [PATCH 2/2] Doesn't dup & freeze already frozen keys in Hash#[]=. Fixes #665 | |
--- | |
kernel/common/hash.rb | 2 +- | |
1 files changed, 1 insertions(+), 1 deletions(-) | |
diff --git a/kernel/common/hash.rb b/kernel/common/hash.rb | |
index 8e6a812..2020c26 100644 | |
--- a/kernel/common/hash.rb | |
+++ b/kernel/common/hash.rb | |
@@ -478,7 +478,7 @@ class Hash | |
# and +value+. If +key+ is a kind of +String+, +key+ is | |
# duped and frozen. | |
def new_entry(key, key_hash, value) | |
- if key.kind_of? String | |
+ if key.kind_of?(String) and !key.frozen? | |
key = key.dup | |
key.freeze | |
end | |
-- | |
1.7.3.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment