Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 65eed013a3c4
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4530d4bf1ea5
Choose a head ref
  • 2 commits
  • 8 files changed
  • 1 contributor

Commits on Apr 6, 2016

  1. Copy the full SHA
    efc66a5 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4530d4b View commit details
Original file line number Diff line number Diff line change
@@ -32,6 +32,8 @@
import org.jruby.truffle.core.array.ArrayHelpers;
import org.jruby.truffle.core.cast.BooleanCastNodeGen;
import org.jruby.truffle.core.module.ModuleOperations;
import org.jruby.truffle.core.rope.Rope;
import org.jruby.truffle.core.rope.RopeOperations;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;
@@ -50,7 +52,6 @@
import org.jruby.truffle.language.parser.ParserContext;
import org.jruby.truffle.language.supercall.SuperCallNode;
import org.jruby.truffle.language.yield.YieldNode;
import org.jruby.util.ByteList;

import java.util.ArrayList;
import java.util.Arrays;
@@ -163,8 +164,8 @@ public InstanceEvalNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isRubyString(string)")
public Object instanceEval(VirtualFrame frame, Object receiver, DynamicObject string, NotProvided block, @Cached("create()")IndirectCallNode callNode) {
ByteList code = StringOperations.getByteListReadOnly(string);
final Source source = Source.fromText(code, "(eval)");
final Rope code = StringOperations.rope(string);
final Source source = Source.fromText(code.toString(), "(eval)");
final RubyRootNode rootNode = getContext().getCodeLoader().parse(source, code.getEncoding(), ParserContext.EVAL, null, true, this);
final CodeLoader.DeferredCall deferredCall = getContext().getCodeLoader().prepareExecute(ParserContext.EVAL, DeclarationContext.INSTANCE_EVAL, rootNode, null, receiver);
return callNode.call(frame, deferredCall.getCallTarget(), deferredCall.getArguments());
Original file line number Diff line number Diff line change
@@ -128,7 +128,6 @@
import org.jruby.truffle.language.parser.jruby.TranslatorDriver;
import org.jruby.truffle.language.threadlocal.ThreadLocalObject;
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.util.ByteList;

import java.io.BufferedReader;
import java.io.File;
@@ -683,7 +682,7 @@ private CodeLoader.DeferredCall doEvalX(DynamicObject rubySource,
String filename,
int line,
boolean ownScopeForAssignments) {
ByteList code = StringOperations.getByteListReadOnly(rubySource);
final Rope code = StringOperations.rope(rubySource);

// TODO (pitr 15-Oct-2015): fix this ugly hack, required for AS, copy-paste
final String space = new String(new char[Math.max(line - 1, 0)]).replace("\0", "\n");
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@
import org.jruby.truffle.core.kernel.KernelNodes;
import org.jruby.truffle.core.kernel.KernelNodesFactory;
import org.jruby.truffle.core.method.MethodFilter;
import org.jruby.truffle.core.rope.Rope;
import org.jruby.truffle.core.string.StringNodes;
import org.jruby.truffle.core.string.StringNodesFactory;
import org.jruby.truffle.core.string.StringOperations;
@@ -94,7 +95,6 @@
import org.jruby.truffle.language.parser.jruby.Translator;
import org.jruby.truffle.language.yield.YieldNode;
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.util.ByteList;
import org.jruby.util.IdUtil;

import java.util.ArrayList;
@@ -670,7 +670,7 @@ private Object classEvalSource(VirtualFrame frame, DynamicObject module, Dynamic
@TruffleBoundary
private CodeLoader.DeferredCall classEvalSource(DynamicObject module, DynamicObject rubySource, String file, int line) {
assert RubyGuards.isRubyString(rubySource);
ByteList code = StringOperations.getByteListReadOnly(rubySource);
final Rope code = StringOperations.rope(rubySource);

final MaterializedFrame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend()
.getFrame(FrameInstance.FrameAccess.MATERIALIZE, true).materialize();
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
* GNU Lesser General Public License version 2.1
*
*
* Some of the code in this class is modified from org.jruby.runtime.Helpers,
* Some of the code in this class is modified from org.jruby.runtime.Helpers and org.jruby.util.StringSupport,
* licensed under the same EPL1.0/GPL 2.0/LGPL 2.1 used throughout.
*
* Contains code modified from ByteList's ByteList.java
@@ -30,6 +30,7 @@
import org.jruby.Ruby;
import org.jruby.RubyEncoding;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeable;
import org.jruby.util.StringSupport;
import org.jruby.util.io.EncodingUtils;

@@ -431,6 +432,51 @@ public static int cmp(Rope string, Rope other) {
return size == other.realSize() ? 0 : size == len ? -1 : 1;
}

@TruffleBoundary
public static Encoding areCompatible(Rope rope, Rope other) {
// Taken from org.jruby.util.StringSupport.areCompatible.

Encoding enc1 = rope.getEncoding();
Encoding enc2 = other.getEncoding();

if (enc1 == enc2) return enc1;

if (other.isEmpty()) return enc1;
if (rope.isEmpty()) {
return (enc1.isAsciiCompatible() && isAsciiOnly(other)) ? enc1 : enc2;
}

if (!enc1.isAsciiCompatible() || !enc2.isAsciiCompatible()) return null;

return RubyEncoding.areCompatible(enc1, rope.getCodeRange().toInt(), enc2, other.getCodeRange().toInt());
}

public static boolean isAsciiOnly(Rope rope) {
// Taken from org.jruby.util.StringSupport.isAsciiOnly.

return rope.getEncoding().isAsciiCompatible() && rope.getCodeRange() == CR_7BIT;
}

public static boolean areComparable(Rope rope, Rope other) {
// Taken from org.jruby.util.StringSupport.areComparable.

if (rope.getEncoding() == other.getEncoding() ||
rope.isEmpty() || other.isEmpty()) return true;
return areComparableViaCodeRange(rope, other);
}

public static boolean areComparableViaCodeRange(Rope string, Rope other) {
// Taken from org.jruby.util.StringSupport.areComparableViaCodeRange.

CodeRange cr1 = string.getCodeRange();
CodeRange cr2 = other.getCodeRange();

if (cr1 == CR_7BIT && (cr2 == CR_7BIT || other.getEncoding().isAsciiCompatible())) return true;
if (cr2 == CR_7BIT && string.getEncoding().isAsciiCompatible()) return true;
return false;
}


public static ByteList getByteListReadOnly(Rope rope) {
return rope.getUnsafeByteList();
}
Original file line number Diff line number Diff line change
@@ -859,8 +859,8 @@ public int getaddrinfoNil(DynamicObject hostName, DynamicObject serviceName, Dyn
@Specialization(guards = {"isRubyString(hostName)", "isRubyString(serviceName)", "isRubyPointer(hintsPointer)", "isRubyPointer(resultsPointer)"})
public int getaddrinfoString(DynamicObject hostName, DynamicObject serviceName, DynamicObject hintsPointer, DynamicObject resultsPointer) {
return nativeSockets().getaddrinfo(
StringOperations.getByteListReadOnly(hostName),
StringOperations.getByteListReadOnly(serviceName),
StringOperations.rope(hostName).toString(),
StringOperations.rope(serviceName).toString(),
Layouts.POINTER.getPointer(hintsPointer),
Layouts.POINTER.getPointer(resultsPointer));
}
@@ -869,7 +869,7 @@ public int getaddrinfoString(DynamicObject hostName, DynamicObject serviceName,
@Specialization(guards = {"isRubyString(hostName)", "isNil(serviceName)", "isRubyPointer(hintsPointer)", "isRubyPointer(resultsPointer)"})
public int getaddrinfo(DynamicObject hostName, DynamicObject serviceName, DynamicObject hintsPointer, DynamicObject resultsPointer) {
return nativeSockets().getaddrinfo(
StringOperations.getByteListReadOnly(hostName),
StringOperations.rope(hostName).toString(),
null,
Layouts.POINTER.getPointer(hintsPointer),
Layouts.POINTER.getPointer(resultsPointer));
Original file line number Diff line number Diff line change
@@ -1675,12 +1675,12 @@ public Object stringSubstring(DynamicObject string, int beg, int len) {
}
return makeRope(string, p - s, e - p);
} else {
beg += StringSupport.strLengthFromRubyString(StringOperations.getCodeRangeableReadOnly(string), enc);
beg += rope.characterLength();
if (beg < 0) {
return nil();
}
}
} else if (beg > 0 && beg > StringSupport.strLengthFromRubyString(StringOperations.getCodeRangeableReadOnly(string), enc)) {
} else if (beg > 0 && beg > rope.characterLength()) {
return nil();
}
if (len == 0) {
Original file line number Diff line number Diff line change
@@ -361,10 +361,13 @@ public CompareNode(RubyContext context, SourceSection sourceSection) {
public int compare(DynamicObject a, DynamicObject b) {
// Taken from org.jruby.RubyString#op_cmp

final int ret = RopeOperations.cmp(rope(a), rope(b));
final Rope firstRope = rope(a);
final Rope secondRope = rope(b);

if ((ret == 0) && !StringSupport.areComparable(StringOperations.getCodeRangeableReadOnly(a), StringOperations.getCodeRangeableReadOnly(b))) {
return encoding(a).getIndex() > encoding(b).getIndex() ? 1 : -1;
final int ret = RopeOperations.cmp(firstRope, secondRope);

if ((ret == 0) && !RopeOperations.areComparable(firstRope, secondRope)) {
return firstRope.getEncoding().getIndex() > secondRope.getEncoding().getIndex() ? 1 : -1;
}

return ret;
@@ -734,7 +737,7 @@ public CaseCmpNode(RubyContext context, SourceSection sourceSection) {
public Object caseCmpSingleByte(DynamicObject string, DynamicObject other) {
// Taken from org.jruby.RubyString#casecmp19.

if (StringSupport.areCompatible(StringOperations.getCodeRangeableReadOnly(string), StringOperations.getCodeRangeableReadOnly(other)) == null) {
if (RopeOperations.areCompatible(rope(string), rope(other)) == null) {
return nil();
}

@@ -746,7 +749,7 @@ public Object caseCmpSingleByte(DynamicObject string, DynamicObject other) {
public Object caseCmp(DynamicObject string, DynamicObject other) {
// Taken from org.jruby.RubyString#casecmp19 and

final Encoding encoding = StringSupport.areCompatible(StringOperations.getCodeRangeableReadOnly(string), StringOperations.getCodeRangeableReadOnly(other));
final Encoding encoding = RopeOperations.areCompatible(rope(string), rope(other));

if (encoding == null) {
return nil();
Original file line number Diff line number Diff line change
@@ -237,10 +237,10 @@ public DumpStringNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject dumpString(DynamicObject string) {
final StringBuilder builder = new StringBuilder();

final ByteList byteList = StringOperations.getByteListReadOnly(string);
final Rope rope = StringOperations.rope(string);

for (int i = 0; i < byteList.length(); i++) {
builder.append(String.format("\\x%02x", byteList.get(i)));
for (int i = 0; i < rope.byteLength(); i++) {
builder.append(String.format("\\x%02x", rope.get(i)));
}

return createString(StringOperations.encodeRope(builder.toString(), UTF8Encoding.INSTANCE));