Skip to content

Commit

Permalink
[Truffle] We only invoke string_scrub on broken strings, which have a…
Browse files Browse the repository at this point in the history
…t least 1 invalid character.
  • Loading branch information
eregon committed Jan 10, 2017
1 parent 2e89982 commit 8e54fc1
Showing 1 changed file with 0 additions and 10 deletions.
Expand Up @@ -1371,7 +1371,6 @@ public abstract static class ScrubNode extends PrimitiveArrayArgumentsNode {
public DynamicObject scrubAsciiCompat(VirtualFrame frame, DynamicObject string, Object repl, DynamicObject block) {
final Rope rope = rope(string);
final Encoding enc = rope.getEncoding();
boolean foundInvalidChar = false;
Rope buf = RopeConstants.EMPTY_ASCII_8BIT_ROPE;

final byte[] pBytes = rope.getBytes();
Expand All @@ -1394,7 +1393,6 @@ public DynamicObject scrubAsciiCompat(VirtualFrame frame, DynamicObject string,
// p1~p: valid ascii/multibyte chars
// p ~e: invalid bytes + unknown bytes
int clen = enc.maxLength();
foundInvalidChar = true;
if (p1 < p) {
buf = makeConcatNode.executeMake(buf, RopeOperations.create(ArrayUtils.extractRange(pBytes, p1, p), enc, CodeRange.CR_VALID), enc);
}
Expand Down Expand Up @@ -1428,9 +1426,6 @@ public DynamicObject scrubAsciiCompat(VirtualFrame frame, DynamicObject string,
}
}
}
if (!foundInvalidChar && p == e) {
return nil();
}
if (p1 < p) {
buf = makeConcatNode.executeMake(buf, RopeOperations.create(ArrayUtils.extractRange(pBytes, p1, p), enc, CodeRange.CR_VALID), enc);
}
Expand All @@ -1447,7 +1442,6 @@ public DynamicObject scrubAsciiCompat(VirtualFrame frame, DynamicObject string,
public DynamicObject scrubAscciIncompatible(VirtualFrame frame, DynamicObject string, Object repl, DynamicObject block) {
final Rope rope = rope(string);
final Encoding enc = rope.getEncoding();
boolean foundInvalidChar = false;
Rope buf = RopeConstants.EMPTY_ASCII_8BIT_ROPE;

final byte[] pBytes = rope.getBytes();
Expand All @@ -1464,7 +1458,6 @@ public DynamicObject scrubAscciIncompatible(VirtualFrame frame, DynamicObject st
} else if (MBCLEN_CHARFOUND_P(ret)) {
p += MBCLEN_CHARFOUND_LEN(ret);
} else if (MBCLEN_INVALID_P(ret)) {
foundInvalidChar = true;
final int q = p;
int clen = enc.maxLength();

Expand Down Expand Up @@ -1496,9 +1489,6 @@ public DynamicObject scrubAscciIncompatible(VirtualFrame frame, DynamicObject st
p1 = p;
}
}
if (!foundInvalidChar && p == e) {
return nil();
}
if (p1 < p) {
buf = makeConcatNode.executeMake(buf, RopeOperations.create(ArrayUtils.extractRange(pBytes, p1, p), enc, CodeRange.CR_VALID), enc);
}
Expand Down

0 comments on commit 8e54fc1

Please sign in to comment.