Skip to content

Commit 6795d6f

Browse files
committed
[GR-19220] String#squeeze fastpath single char case (#2348)
PullRequest: truffleruby/2656
2 parents 3e08219 + 6d2a62b commit 6795d6f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/java/org/truffleruby/core/string/StringNodes.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2524,10 +2524,21 @@ private Object performSqueezeBang(RubyString string, Object[] otherStrings) {
25242524
Rope otherRope = RubyStringLibrary.getUncached().getRope(otherStr);
25252525
Encoding enc = checkEncodingNode.executeCheckEncoding(string, otherStr);
25262526
final boolean squeeze[] = new boolean[StringSupport.TRANS_SIZE + 1];
2527-
StringSupport.TrTables tables = StringSupport.trSetupTable(otherRope, squeeze, null, true, enc);
25282527

25292528
boolean singlebyte = rope.isSingleByteOptimizable() && otherRope.isSingleByteOptimizable();
25302529

2530+
if (singlebyte && otherRope.byteLength() == 1 && otherStrings.length == 1) {
2531+
squeeze[otherRope.getRawBytes()[0]] = true;
2532+
if (!StringSupport.singleByteSqueeze(buffer, squeeze)) {
2533+
return nil;
2534+
} else {
2535+
string.setRope(RopeOperations.ropeFromRopeBuilder(buffer));
2536+
return string;
2537+
}
2538+
}
2539+
2540+
StringSupport.TrTables tables = StringSupport.trSetupTable(otherRope, squeeze, null, true, enc);
2541+
25312542
for (int i = 1; i < otherStrings.length; i++) {
25322543
otherStr = otherStrings[i];
25332544
otherRope = RubyStringLibrary.getUncached().getRope(otherStr);

0 commit comments

Comments
 (0)