Skip to content

Commit

Permalink
[Truffle] Use jcodings's trascoder DB rather than a hard-coded list t…
Browse files Browse the repository at this point in the history
…o improve start-up time.
  • Loading branch information
nirvdrum committed Mar 28, 2015
1 parent 06e3bff commit 53683ba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7,694 deletions.
Expand Up @@ -19,6 +19,8 @@
import org.jcodings.transcode.EConv;
import org.jcodings.transcode.Transcoder;
import org.jcodings.transcode.TranscoderDB;
import org.jcodings.util.CaseInsensitiveBytesHash;
import org.jcodings.util.Hash;
import org.jruby.Ruby;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
Expand Down Expand Up @@ -122,15 +124,22 @@ public TranscodingMapNode(TranscodingMapNode prev) {
public RubyHash transcodingMap(VirtualFrame frame) {
List<KeyValue> entries = new ArrayList<>();

for (RubyEncoding e : RubyEncoding.cloneEncodingList()) {
final Object upcased = upcaseNode.call(frame, getContext().makeString(e.getName()), "upcase", null);
final Object key = toSymNode.call(frame, upcased, "to_sym", null);
for (CaseInsensitiveBytesHash<TranscoderDB.Entry> sourceEntry : TranscoderDB.transcoders) {
Object key = null;
final Object value = newLookupTableNode.call(frame, getContext().getCoreLibrary().getLookupTableClass(), "new", null);

final Object tupleValues = new Object[2];
for (Hash.HashEntry<TranscoderDB.Entry> destinationEntry : sourceEntry.entryIterator()) {
final TranscoderDB.Entry e = destinationEntry.value;

if (key == null) {
final Object upcased = upcaseNode.call(frame, getContext().makeString(new ByteList(e.getSource())), "upcase", null);
key = toSymNode.call(frame, upcased, "to_sym", null);
}

lookupTableWriteNode.call(frame, value, "[]=", null, key, nil());
final Object upcasedLookupTableKey = upcaseNode.call(frame, getContext().makeString(new ByteList(e.getDestination())), "upcase", null);
final Object lookupTableKey = toSymNode.call(frame, upcasedLookupTableKey, "to_sym", null);
lookupTableWriteNode.call(frame, value, "[]=", null, lookupTableKey, true);
}

entries.add(new KeyValue(key, value));
}
Expand All @@ -139,4 +148,25 @@ public RubyHash transcodingMap(VirtualFrame frame) {
}
}

@RubiniusOnly
@CoreMethod(names = "transcoding_path_lookup", onSingleton = true, required = 2)
public abstract static class TranscodingPathLookupNode extends CoreMethodNode {

public TranscodingPathLookupNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public TranscodingPathLookupNode(TranscodingPathLookupNode prev) {
super(prev);
}

@Specialization
public boolean transcodingPathLookup(RubyString sourceEncodingName, RubyString destinationEncodingName) {
final TranscoderDB.Entry entry = TranscoderDB.getEntry(sourceEncodingName.getByteList().getUnsafeBytes(),
destinationEncodingName.getByteList().getUnsafeBytes());

return entry.getTranscoder() != null;
}
}

}
3 changes: 0 additions & 3 deletions truffle/src/main/ruby/core.rb
Expand Up @@ -89,9 +89,6 @@
# Load delta (ordered according to Rubinius' load_order.txt)
require_relative 'core/rubinius/delta/struct'

# Eagerly-load files that are normally lazily loaded via Rubinius::CodeLoader.require_compiled.
require_relative 'core/rubinius/delta/converter_paths'

# Load JRuby+Truffle classes
require_relative 'core/array'
require_relative 'core/fixnum'
Expand Down

0 comments on commit 53683ba

Please sign in to comment.