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

Commits on Jan 10, 2017

  1. [Truffle] A bit of cleanup.

    eregon committed Jan 10, 2017
    Copy the full SHA
    c7ba64c View commit details
  2. Copy the full SHA
    0bcd0cb View commit details
Showing with 25 additions and 23 deletions.
  1. +25 −23 truffle/src/main/java/org/jruby/truffle/core/string/StringNodes.java
Original file line number Diff line number Diff line change
@@ -1383,23 +1383,21 @@ public abstract static class ScrubNode extends PrimitiveArrayArgumentsNode {
@Child private CallDispatchHeadNode strCompatAndValidNode = DispatchHeadNodeFactory.createMethodCall(true);
@Child private RopeNodes.MakeConcatNode makeConcatNode = RopeNodesFactory.MakeConcatNodeGen.create(null, null, null);

@Specialization
@Specialization(guards = "isValid(string)")
public DynamicObject scrubValid(VirtualFrame frame, DynamicObject string, Object repl, DynamicObject block) {
return nil();
}

@Specialization(guards = "!isValid(string)")
public DynamicObject scrubDefault(VirtualFrame frame, DynamicObject string, Object repl, DynamicObject block,
@Cached("createBinaryProfile()") ConditionProfile validRangeProfile,
@Cached("createBinaryProfile()") ConditionProfile asciiCompatibleProfile) {
final DynamicObject rubyEncoding = getContext().getEncodingManager().getRubyEncoding(StringOperations.encoding(string));
final Rope rope = rope(string);
Rope buf = null;
CodeRange cr = rope.getCodeRange();
final Encoding enc;
final Encoding encidx;
final Encoding enc = rope.getEncoding();
final DynamicObject rubyEncoding = getContext().getEncodingManager().getRubyEncoding(enc);
Rope buf = null;
boolean tainted = false;

if (validRangeProfile.profile(cr == CR_7BIT || cr == CR_VALID)) {
return nil();
}

enc = rope.getEncoding();
if (repl != nil()) {
repl = strCompatAndValidNode.call(frame, string, "str_compat_and_valid", repl, rubyEncoding);
tainted |= isTaintedNode.executeIsTainted(repl);
@@ -1408,7 +1406,6 @@ public DynamicObject scrubDefault(VirtualFrame frame, DynamicObject string, Obje
if (enc.isDummy()) {
return nil();
}
encidx = enc;

final byte[] pBytes = rope.getBytes();
final int e = pBytes.length;
@@ -1428,7 +1425,7 @@ public DynamicObject scrubDefault(VirtualFrame frame, DynamicObject string, Obje
repBytes = replRope.getBytesCopy();
replen = repBytes.length;
rep7bit_p = (replRope.getCodeRange() == CodeRange.CR_7BIT);
} else if (encidx == UTF8Encoding.INSTANCE) {
} else if (enc == UTF8Encoding.INSTANCE) {
repBytes = SCRUB_REPL_UTF8;
replen = repBytes.length;
rep7bit_p = false;
@@ -1487,7 +1484,7 @@ else if (MBCLEN_INVALID_P(ret)) {
}
}
else {
repl = yield(frame, (DynamicObject)block, createString(ArrayUtils.extractRange(pBytes, p, p + clen), enc));
repl = yield(frame, block, createString(ArrayUtils.extractRange(pBytes, p, p + clen), enc));
repl = strCompatAndValidNode.call(frame, string, "str_compat_and_valid", repl, rubyEncoding);
tainted |= isTaintedNode.executeIsTainted(repl);
buf = makeConcatNode.executeMake(buf, rope((DynamicObject)repl), enc);
@@ -1522,7 +1519,7 @@ else if (MBCLEN_INVALID_P(ret)) {
}
}
else {
repl = yield(frame, (DynamicObject)block, createString(ArrayUtils.extractRange(pBytes, p, e), enc));
repl = yield(frame, block, createString(ArrayUtils.extractRange(pBytes, p, e), enc));
repl = strCompatAndValidNode.call(frame, string, "str_compat_and_valid", repl, rubyEncoding);
tainted |= isTaintedNode.executeIsTainted(repl);
buf = makeConcatNode.executeMake(buf, rope((DynamicObject)repl), enc);
@@ -1533,7 +1530,7 @@ else if (MBCLEN_INVALID_P(ret)) {
}
}
else {
/* ASCII incompatible */
/* ASCII incompatible */
int p = 0;
int p1 = 0;
final int mbminlen = enc.minLength();
@@ -1542,13 +1539,13 @@ else if (MBCLEN_INVALID_P(ret)) {
if (repl != nil()) {
final Rope replRope = rope((DynamicObject) repl);
repBytes = replRope.getBytesCopy();
} else if (encidx == UTF16BEEncoding.INSTANCE) {
} else if (enc == UTF16BEEncoding.INSTANCE) {
repBytes = SCRUB_REPL_UTF16BE;
} else if (encidx == UTF16LEEncoding.INSTANCE) {
} else if (enc == UTF16LEEncoding.INSTANCE) {
repBytes = SCRUB_REPL_UTF16LE;
} else if (encidx == UTF32BEEncoding.INSTANCE) {
} else if (enc == UTF32BEEncoding.INSTANCE) {
repBytes = SCRUB_REPL_UTF32BE;
} else if (encidx == UTF32LEEncoding.INSTANCE) {
} else if (enc == UTF32LEEncoding.INSTANCE) {
repBytes = SCRUB_REPL_UTF32LE;
} else {
repBytes = SCRUB_REPL_ASCII;
@@ -1567,7 +1564,7 @@ else if (MBCLEN_INVALID_P(ret)) {
int clen = enc.maxLength();
if (buf == null) {
buf = RopeConstants.EMPTY_ASCII_8BIT_ROPE;
};
}

if (p > p1) {
buf = makeConcatNode.executeMake(buf, RopeOperations.create(ArrayUtils.extractRange(pBytes, p1, p), ASCIIEncoding.INSTANCE, CodeRange.CR_VALID), enc);
@@ -1588,7 +1585,7 @@ else if (MBCLEN_INVALID_P(ret)) {
if (repBytes != null) {
buf = makeConcatNode.executeMake(buf, RopeOperations.create(ArrayUtils.extractRange(repBytes, 0, repBytes.length), ASCIIEncoding.INSTANCE, CodeRange.CR_VALID), enc);
} else {
repl = yield(frame, (DynamicObject) block, createString(ArrayUtils.extractRange(pBytes, p, e), enc));
repl = yield(frame, block, createString(ArrayUtils.extractRange(pBytes, p, e), enc));
repl = strCompatAndValidNode.call(frame, string, "str_compat_and_valid", repl, rubyEncoding);
tainted |= isTaintedNode.executeIsTainted(repl);
buf = makeConcatNode.executeMake(buf, rope((DynamicObject) repl), enc);
@@ -1612,7 +1609,7 @@ else if (MBCLEN_INVALID_P(ret)) {
buf = makeConcatNode.executeMake(buf, RopeOperations.create(ArrayUtils.extractRange(repBytes, 0, repBytes.length), ASCIIEncoding.INSTANCE, CodeRange.CR_VALID), enc);
}
else {
repl = yield(frame, (DynamicObject)block, createString(ArrayUtils.extractRange(pBytes, p, e), enc));
repl = yield(frame, block, createString(ArrayUtils.extractRange(pBytes, p, e), enc));
repl = strCompatAndValidNode.call(frame, string, "str_compat_and_valid", repl, rubyEncoding);
tainted |= isTaintedNode.executeIsTainted(repl);
buf = makeConcatNode.executeMake(buf, rope((DynamicObject)repl), enc);
@@ -1634,6 +1631,11 @@ else if (MBCLEN_INVALID_P(ret)) {
return resultString;
}

protected boolean isValid(DynamicObject string) {
CodeRange cr = rope(string).getCodeRange();
return cr == CR_7BIT || cr == CR_VALID;
}

public Object yield(VirtualFrame frame, DynamicObject block, Object... arguments) {
return yieldNode.dispatch(frame, block, arguments);
}