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: 2e9bd7d6d1e5
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6ef317b7cdaa
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Feb 3, 2016

  1. Copy the full SHA
    71a797c View commit details
  2. Copy the full SHA
    6ef317b View commit details
3 changes: 1 addition & 2 deletions test/truffle/compiler/pe/core/eval_pe.rb
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@

example "eval('[1, 2, 3]')[1]", 2

# TODO (nirvdrum 27-Jan-16): This started timing out after moving some things to ropes. It's probably a matter of caching that generally needs to be fixed.
tagged_example "eval([1, 2, 3].inspect)[1]", 2
example "eval([1, 2, 3].inspect)[1]", 2

counter_example "eval(rand.to_s)"
1 change: 1 addition & 0 deletions test/truffle/compiler/pe/core/string_pe.rb
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@

example "Truffle::Primitive.create_simple_string.length", simple_string.length
example "Truffle::Primitive.create_simple_string.getbyte(0)", simple_string.getbyte(0)
example "Truffle::Primitive.create_simple_string.ord", simple_string.ord

example "'abc'.length", 3
example "'こにちわ'.length", 4
22 changes: 17 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -68,7 +68,6 @@
import org.jruby.truffle.runtime.rope.Rope;
import org.jruby.truffle.runtime.rope.RopeOperations;
import org.jruby.util.*;
import org.jruby.util.io.EncodingUtils;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
@@ -1571,19 +1570,31 @@ public DynamicObject setNumBytes(DynamicObject string, int count) {
}

@CoreMethod(names = "ord")
@ImportStatic(StringGuards.class)
public abstract static class OrdNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
@Specialization(guards = "isEmpty(string)")
public int ordEmpty(DynamicObject string) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("empty string", this));
}

// TODO (nirvdrum 03-Feb-16): Is it possible to have a single-byte optimizable string that isn't ASCII-compatible?
@Specialization(guards = { "!isEmpty(string)", "isSingleByteOptimizable(string)" })
public int ordAsciiOnly(DynamicObject string) {
return rope(string).get(0) & 0xff;
}

@Specialization(guards = { "!isEmpty(string)", "!isSingleByteOptimizable(string)" })
public int ord(DynamicObject string) {
final StringCodeRangeableWrapper codeRangeable = StringOperations.getCodeRangeableReadOnly(string);
final ByteList bytes = codeRangeable.getByteList();
final Rope rope = rope(string);

try {
return codePoint(EncodingUtils.STR_ENC_GET(codeRangeable), bytes.getUnsafeBytes(), bytes.begin(), bytes.begin() + bytes.realSize());
return codePoint(rope.getEncoding(), rope.getBytes(), rope.begin(), rope.begin() + rope.realSize());
} catch (IllegalArgumentException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(e.getMessage(), this));
@@ -1594,6 +1605,7 @@ public int ord(DynamicObject string) {
private int codePoint(Encoding encoding, byte[] bytes, int p, int end) {
return StringSupport.codePoint(encoding, bytes, p, end);
}

}

@CoreMethod(names = "replace", required = 1, raiseIfFrozenSelf = true, taintFromParameter = 0)
Original file line number Diff line number Diff line change
@@ -32,12 +32,12 @@ public ConcatRope(Rope left, Rope right, Encoding encoding, CodeRange codeRange,

@Override
@TruffleBoundary
public int get(int index) {
public byte getByteSlow(int index) {
if (index < left.byteLength()) {
return left.get(index);
return left.getByteSlow(index);
}

return right.get(index - left.byteLength());
return right.getByteSlow(index - left.byteLength());
}

@Override
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public LeafRope(byte[] bytes, Encoding encoding, CodeRange codeRange, boolean si
}

@Override
public int get(int index) {
public byte getByteSlow(int index) {
return getRawBytes()[index];
}

10 changes: 9 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/runtime/rope/Rope.java
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ public final ByteList getUnsafeByteList() {

public final ByteList toByteListCopy() { return new ByteList(getBytes(), getEncoding(), true); }

public abstract int get(int index);
protected abstract byte getByteSlow(int index);

public final byte[] getRawBytes() {
return bytes;
@@ -141,4 +141,12 @@ public boolean equals(Object o) {
return false;
}

public byte get(int index) {
if (bytes != null) {
return bytes[index];
}

return getByteSlow(index);
}

}
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@ public SubstringRope(Rope child, int offset, int byteLength, int characterLength
}

@Override
public int get(int index) {
return child.get(index + offset);
public byte getByteSlow(int index) {
return child.getByteSlow(index + offset);
}

@Override