Skip to content

Commit

Permalink
[Truffle] Get rid of StringOperations.createRope().
Browse files Browse the repository at this point in the history
* Use encodeRope().
  • Loading branch information
eregon committed Nov 8, 2016
1 parent b11a300 commit 00fa048
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Expand Up @@ -169,11 +169,6 @@ public static Rope encodeRope(CharSequence value, Encoding encoding) {
return encodeRope(value, encoding, CodeRange.CR_UNKNOWN);
}

@TruffleBoundary
public static Rope createRope(String s, Encoding encoding) {
return RopeOperations.create(ByteList.encode(s, "ISO-8859-1"), encoding, CodeRange.CR_UNKNOWN);
}

public static ByteList getByteListReadOnly(DynamicObject object) {
return RopeOperations.getByteListReadOnly(rope(object));
}
Expand Down
Expand Up @@ -20,7 +20,6 @@
import org.jruby.truffle.core.rope.RopeOperations;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.util.ByteList;
import org.jruby.util.IdUtil;

import java.lang.ref.Reference;
Expand Down Expand Up @@ -70,7 +69,9 @@ public DynamicObject getSymbol(String stringKey) {
return symbol;
}

final Rope rope = StringOperations.createRope(stringKey, USASCIIEncoding.INSTANCE);
// TODO (eregon, 8 Nov. 2016): This doesn't sound right,
// maybe it should become UTF-8 if it's not 7-bit?
final Rope rope = StringOperations.encodeRope(stringKey, USASCIIEncoding.INSTANCE);
symbol = getDeduplicatedSymbol(rope);

stringSymbolMap.put(stringKey, new WeakReference<DynamicObject>(symbol));
Expand Down Expand Up @@ -126,7 +127,7 @@ private DynamicObject getDeduplicatedSymbol(Rope rope) {
}

private DynamicObject createSymbol(Rope rope) {
final String string = ByteList.decode(rope.getBytes(), 0, rope.byteLength(), "ISO-8859-1");
final String string = RopeOperations.decodeRope(rope);
// Symbol has to have reference to its SymbolEquality otherwise it would be GCed.
final SymbolEquality equalityWrapper = new SymbolEquality();
final DynamicObject symbol = Layouts.SYMBOL.createSymbol(
Expand Down
Expand Up @@ -59,6 +59,7 @@
import org.jruby.truffle.core.rope.CodeRange;
import org.jruby.truffle.core.rope.Rope;
import org.jruby.truffle.core.rope.RopeConstants;
import org.jruby.truffle.core.rope.RopeOperations;
import org.jruby.truffle.core.rubinius.RubiniusLastStringReadNode;
import org.jruby.truffle.core.rubinius.RubiniusLastStringWriteNodeGen;
import org.jruby.truffle.core.string.InterpolatedStringNode;
Expand Down Expand Up @@ -3031,7 +3032,16 @@ public RubyNode visitStrNode(StrParseNode node) {

@Override
public RubyNode visitSymbolNode(SymbolParseNode node) {
final Rope rope = StringOperations.createRope(node.getName(), node.getEncoding());
String name = node.getName();
// The symbol is passed as a String but it's really
// "interpret the char[] as a byte[] with the given encoding".
byte[] bytes = new byte[name.length()];
for (int i = 0; i < name.length(); i++) {
char val = name.charAt(i);
assert val >= 0 && val < 256;
bytes[i] = (byte) (val & 0xFF);
}
final Rope rope = RopeOperations.create(bytes, node.getEncoding(), CodeRange.CR_UNKNOWN);
final RubyNode ret = new ObjectLiteralNode(context, translate(node.getPosition()).toSourceSection(source), context.getSymbolTable().getSymbol(rope));
return addNewlineIfNeeded(node, ret);
}
Expand Down

0 comments on commit 00fa048

Please sign in to comment.