Skip to content

Commit

Permalink
Re-introduce small hash for memory savings and small speed up for sma…
Browse files Browse the repository at this point in the history
…ll hashes
  • Loading branch information
enebo committed May 26, 2015
1 parent 25e14ae commit 89c8525
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Expand Up @@ -1031,9 +1031,17 @@ public static Encoding retrieveJCodingsEncoding(ThreadContext context, String na

@JIT
public static RubyHash constructHashFromArray(Ruby runtime, IRubyObject[] pairs) {
RubyHash hash = RubyHash.newHash(runtime);
int length = pairs.length / 2;
boolean useSmallHash = length <= 10;

RubyHash hash = useSmallHash ? RubyHash.newHash(runtime) : RubyHash.newSmallHash(runtime);
for (int i = 0; i < pairs.length;) {
hash.fastASet(runtime, pairs[i++], pairs[i++], true);
if (useSmallHash) {
hash.fastASetSmall(runtime, pairs[i++], pairs[i++], true);
} else {
hash.fastASet(runtime, pairs[i++], pairs[i++], true);
}

}
return hash;
}
Expand Down

0 comments on commit 89c8525

Please sign in to comment.