Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Truffle] Tidy up RubyHash.
  • Loading branch information
chrisseaton committed Dec 16, 2014
commit 579881f0be2050b41372b2771484d3ab4a30a5a4
89 changes: 45 additions & 44 deletions core/src/main/java/org/jruby/truffle/nodes/core/HashNodes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.hash.Entry;
import org.jruby.truffle.runtime.hash.HashOperations;
import org.jruby.truffle.runtime.methods.RubyMethod;
import org.jruby.util.cli.Options;

Expand Down Expand Up @@ -597,7 +598,7 @@ private static void exec(RubyContext context, String[] commandLine) {

final RubyHash env = context.getCoreLibrary().getENV();

for (Entry entry : env.verySlowToEntries()) {
for (Entry entry : HashOperations.verySlowToEntries(env)) {
builder.environment().put(entry.getKey().toString(), entry.getValue().toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.hash.Entry;
import org.jruby.truffle.runtime.hash.HashOperations;

/**
* Represents an expression that is evaluated by running it as a system command via forking and
Expand All @@ -44,7 +45,7 @@ public Object execute(VirtualFrame frame) {
final List<String> envp = new ArrayList<>();

// TODO(CS): cast
for (Entry entry : env.verySlowToEntries()) {
for (Entry entry : HashOperations.verySlowToEntries(env)) {
envp.add(entry.getKey().toString() + "=" + entry.getValue().toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.hash.Entry;
import org.jruby.truffle.runtime.hash.HashOperations;

import java.util.*;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but JRuby core prefers these be expanded.


Expand All @@ -39,7 +40,7 @@ protected HashLiteralNode(RubyContext context, SourceSection sourceSection, Ruby
public static HashLiteralNode create(RubyContext context, SourceSection sourceSection, RubyNode[] keyValues) {
if (keyValues.length == 0) {
return new EmptyHashLiteralNode(context, sourceSection);
} else if (keyValues.length <= RubyHash.HASHES_SMALL * 2) {
} else if (keyValues.length <= HashOperations.SMALL_HASH_SIZE * 2) {
return new SmallHashLiteralNode(context, sourceSection, keyValues);
} else {
return new GenericHashLiteralNode(context, sourceSection, keyValues);
Expand Down Expand Up @@ -87,7 +88,7 @@ public SmallHashLiteralNode(RubyContext context, SourceSection sourceSection, Ru
@ExplodeLoop
@Override
public RubyHash executeRubyHash(VirtualFrame frame) {
final Object[] storage = new Object[RubyHash.HASHES_SMALL * 2];
final Object[] storage = new Object[HashOperations.SMALL_HASH_SIZE * 2];

int position = 0;

Expand Down Expand Up @@ -135,7 +136,7 @@ public RubyHash executeRubyHash(VirtualFrame frame) {
entries.add(new Entry(key, value));
}

return RubyHash.verySlowFromEntries(getContext(), entries);
return HashOperations.verySlowFromEntries(getContext(), entries);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.hash.Entry;
import org.jruby.truffle.runtime.hash.HashOperations;
import org.jruby.truffle.runtime.methods.*;

/**
Expand Down Expand Up @@ -49,7 +50,7 @@ public void executeVoid(VirtualFrame frame) {
}

if (!keywordsRest && arity.hasKeywords() && getKeywordsHash(frame) != null) {
for (Entry entry : getKeywordsHash(frame).verySlowToEntries()) {
for (Entry entry : HashOperations.verySlowToEntries(getKeywordsHash(frame))) {
for (String keyword : keywords) {
if (!keyword.toString().equals(entry.getKey().toString())) {
throw new RaiseException(getContext().getCoreLibrary().argumentError("unknown keyword: " + entry.getKey().toString(), this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.hash.Entry;
import org.jruby.truffle.runtime.hash.HashOperations;

public class ReadKeywordArgumentNode extends RubyNode {

Expand All @@ -42,7 +43,7 @@ public Object execute(VirtualFrame frame) {

Object value = null;

for (Entry entry : hash.verySlowToEntries()) {
for (Entry entry : HashOperations.verySlowToEntries(hash)) {
if (entry.getKey().toString().equals(name)) {
value = entry.getValue();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.hash.Entry;
import org.jruby.truffle.runtime.hash.HashOperations;

import java.util.*;

Expand All @@ -42,7 +43,7 @@ public Object execute(VirtualFrame frame) {

final List<Entry> entries = new ArrayList<>();

outer: for (Entry entry : hash.verySlowToEntries()) {
outer: for (Entry entry : HashOperations.verySlowToEntries(hash)) {
for (String excludedKeyword : excludedKeywords) {
if (excludedKeyword.toString().equals(entry.getKey().toString())) {
continue outer;
Expand All @@ -52,7 +53,7 @@ public Object execute(VirtualFrame frame) {
entries.add(new Entry(entry.getKey(), entry.getValue()));
}

return RubyHash.verySlowFromEntries(getContext(), entries);
return HashOperations.verySlowFromEntries(getContext(), entries);
}

private RubyHash getKeywordsHash(VirtualFrame frame) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.hash.Entry;
import org.jruby.truffle.runtime.hash.HashOperations;
import org.jruby.truffle.runtime.rubinius.RubiniusLibrary;
import org.jruby.truffle.translator.TranslatorDriver;
import org.jruby.util.cli.Options;
Expand Down Expand Up @@ -742,7 +743,7 @@ private RubyHash getSystemEnv() {
entries.add(new Entry(context.makeString(variable.getKey()), context.makeString(variable.getValue())));
}

return RubyHash.verySlowFromEntries(context, entries);
return HashOperations.verySlowFromEntries(context, entries);
}

public ArrayNodes.MinBlock getArrayMinBlock() {
Expand Down
Loading