Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
complimentary patch to fix regression rehashing hashing fix (this and…
… previous patch prepared by nahi)
  • Loading branch information
enebo committed Dec 27, 2011
1 parent cc77504 commit 2f607d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions spec/regression/JRUBY-6209_hash_rehash_spec.rb
@@ -0,0 +1,13 @@
describe "JRUBY-6209: Hash#rehash does not work under some condition" do
it "works even it contains a key where #hash is negative" do
a = "ASCII"
b = "\xE3\x81\x82" # Japanese 'a' in UTF-8, but encoding is not related
# b.hash < 0 at this moment, but there's no reason to be negative in the future.
# b.hash.should < 0
key = [a]
hash = Hash[key => 100]
key[0] = b
hash.rehash
hash[key].should == 100
end
end
2 changes: 1 addition & 1 deletion src/org/jruby/RubyHash.java
Expand Up @@ -824,7 +824,7 @@ public RubyHash rehash() {
oldTable[j] = null;
while (entry != null) {
RubyHashEntry next = entry.next;
entry.hash = entry.key.hashCode(); // update the hash value
entry.hash = hashValue(entry.key.hashCode()); // update the hash value
int i = bucketIndex(entry.hash, newTable.length);
entry.next = newTable[i];
newTable[i] = entry;
Expand Down

0 comments on commit 2f607d2

Please sign in to comment.