Skip to content

Commit

Permalink
[Truffle] Removed caching of ByteList in Rope.
Browse files Browse the repository at this point in the history
Most ropes never need a ByteList, so paying the cost of the reference in every rope was not ideal. Moreover, most repeated usages of the Rope -> ByteList adapter (those that would benefit from a cached object) are found in the regexp subsystem and all of that is slow path currently. Thus, removing this reference should save RAM and have negligible impact on performance.
nirvdrum committed Apr 6, 2016
1 parent 4530d4b commit 315c1ef
Showing 2 changed files with 1 addition and 11 deletions.
9 changes: 0 additions & 9 deletions truffle/src/main/java/org/jruby/truffle/core/rope/Rope.java
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ public abstract class Rope {
private final int ropeDepth;
private int hashCode = 0;
private byte[] bytes;
private ByteList unsafeByteList;

protected Rope(Encoding encoding, CodeRange codeRange, boolean singleByteOptimizable, int byteLength, int characterLength, int ropeDepth, byte[] bytes) {
this.encoding = encoding;
@@ -50,14 +49,6 @@ public boolean isEmpty() {
return byteLength == 0;
}

final ByteList getUnsafeByteList() {
if (unsafeByteList == null) {
unsafeByteList = new ByteList(getBytes(), getEncoding(), false);
}

return unsafeByteList;
}

protected abstract byte getByteSlow(int index);

public final byte[] getRawBytes() {
Original file line number Diff line number Diff line change
@@ -30,7 +30,6 @@
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;

@@ -478,7 +477,7 @@ public static boolean areComparableViaCodeRange(Rope string, Rope other) {


public static ByteList getByteListReadOnly(Rope rope) {
return rope.getUnsafeByteList();
return new ByteList(rope.getBytes(), rope.getEncoding(), false);
}

public static ByteList toByteListCopy(Rope rope) {

0 comments on commit 315c1ef

Please sign in to comment.