Skip to content

Commit

Permalink
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
import org.jruby.Ruby;
import org.jruby.RubyEncoding;
import org.jruby.util.ByteList;
import org.jruby.util.Memo;
import org.jruby.util.StringSupport;
import org.jruby.util.io.EncodingUtils;

@@ -285,18 +286,22 @@ public static void visitBytes(Rope rope, BytesVisitor visitor, int offset, int l

@TruffleBoundary
public static byte[] extractRange(Rope rope, int offset, int length) {
final ByteList result = new ByteList(length);
final byte[] result = new byte[length];

final Memo<Integer> resultPosition = new Memo<>(0);

visitBytes(rope, new BytesVisitor() {

@Override
public void accept(byte[] bytes, int offset, int length) {
result.append(bytes, offset, length);
final int resultPositionValue = resultPosition.get();
System.arraycopy(bytes, offset, result, resultPositionValue, length);
resultPosition.set(resultPositionValue + length);
}

}, offset, length);

return result.getUnsafeBytes();
return result;
}

/**

0 comments on commit dd63f00

Please sign in to comment.