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: 2bafb787055a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e5997f2ae250
Choose a head ref
  • 9 commits
  • 8 files changed
  • 1 contributor

Commits on Dec 26, 2016

  1. Copy the full SHA
    95a4d06 View commit details
  2. Copy the full SHA
    7c1e632 View commit details
  3. Copy the full SHA
    e32d9bf View commit details
  4. Copy the full SHA
    b4e14b0 View commit details
  5. Copy the full SHA
    30e2889 View commit details
  6. Copy the full SHA
    850b13d View commit details
  7. Copy the full SHA
    d2bce54 View commit details
  8. Copy the full SHA
    e04b941 View commit details
  9. Copy the full SHA
    e5997f2 View commit details
34 changes: 16 additions & 18 deletions truffle/src/main/java/org/jruby/truffle/parser/ParserByteList.java
Original file line number Diff line number Diff line change
@@ -39,8 +39,7 @@

import org.jcodings.Encoding;
import org.jcodings.ascii.AsciiTables;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.truffle.core.string.ByteList;
import org.jcodings.specific.ASCIIEncoding;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
@@ -50,18 +49,21 @@ public class ParserByteList {
private final byte[] bytes;
private final int start;
private final int length;
private Encoding encoding;
private final Encoding encoding;

public ParserByteList(byte[] bytes) {
this(bytes, 0, bytes.length, USASCIIEncoding.INSTANCE);
this(bytes, ASCIIEncoding.INSTANCE);
}

public ParserByteList(byte[] bytes, Encoding encoding) {
this(bytes, 0, bytes.length, encoding);
}

public ParserByteList(byte[] bytes, int start, int length, Encoding encoding) {
ByteList byteList = new ByteList(bytes, start, length, encoding, false);
this.bytes = byteList.bytes();
this.start = 0;
this.length = byteList.length();
this.encoding = byteList.getEncoding();
this.bytes = bytes;
this.start = start;
this.length = length;
this.encoding = encoding;
}

public int getStart() {
@@ -76,8 +78,8 @@ public Encoding getEncoding() {
return encoding;
}

public void setEncoding(Encoding encoding) {
this.encoding = encoding;
public ParserByteList withEncoding(Encoding encoding) {
return new ParserByteList(bytes, start, length, encoding);
}

public ParserByteList makeShared(int sharedStart, int sharedLength) {
@@ -132,15 +134,11 @@ public int charAt(int index) {
}

public String toString() {
return new String(Arrays.copyOfRange(bytes, start, length), StandardCharsets.US_ASCII);
}

public ByteList toByteList() {
return new ByteList(bytes, start, length, encoding, true);
return new String(Arrays.copyOfRange(bytes, start, start + length), StandardCharsets.US_ASCII);
}

public ParserByteListBuilder toBuilder() {
return new ParserByteListBuilder(Arrays.copyOfRange(bytes, start, length), encoding);
public byte[] getUnsafeBytes() {
return bytes;
}

}
Original file line number Diff line number Diff line change
@@ -10,50 +10,20 @@
package org.jruby.truffle.parser;

import org.jcodings.Encoding;
import org.jruby.truffle.core.string.ByteList;
import org.jcodings.specific.ASCIIEncoding;

import java.util.Arrays;

public class ParserByteListBuilder {

private byte[] bytes;
private int start;
private int length;
private Encoding encoding;

public ParserByteListBuilder(byte[] bytes, Encoding encoding) {
this.bytes = bytes;
start = 0;
length = bytes.length;
this.encoding = encoding;
}

public ParserByteListBuilder(ByteList byteList) {
fromByteList(byteList);
}

public ParserByteListBuilder(int capacity) {
this(new ByteList(capacity));
}

public ParserByteListBuilder() {
this(new ByteList());
}

public ParserByteListBuilder(ParserByteListBuilder other) {
this(other.toByteList());
}

public static ParserByteListBuilder create(String string) {
return new ParserByteListBuilder(ByteList.create(string));
}

public int getStart() {
return start;
}

public void setStart(int start) {
this.start = start;
bytes = new byte[16];
length = 0;
encoding = ASCIIEncoding.INSTANCE;
}

public int getLength() {
@@ -73,53 +43,41 @@ public void setEncoding(Encoding encoding) {
}

public void append(int b) {
fromByteList(toByteList().append(b));
append((byte) b);
}

public void append(byte b) {
grow(1);
bytes[length] = b;
length++;
}

public void append(byte[] bytes) {
fromByteList(toByteList().append(bytes));
append(bytes, 0, bytes.length);
}

public void append(ParserByteListBuilder other, int start, int length) {
fromByteList(toByteList().append(other.toByteList(), start, length));
public void append(ParserByteList other) {
append(other.getUnsafeBytes(), other.getStart(), other.getLength());
}

public void append(ParserByteListBuilder other) {
fromByteList(toByteList().append(other.toByteList()));
public void append(byte[] appendBytes, int appendStart, int appendLength) {
grow(appendLength);
System.arraycopy(appendBytes, appendStart, bytes, length, appendLength);
length += appendLength;
}

public void ensure(int length) {
bytes = Arrays.copyOf(bytes, Math.max(bytes.length, length));
public void grow(int extra) {
if (length + extra > bytes.length) {
bytes = Arrays.copyOf(bytes, (length + extra) * 2);
}
}

public byte[] getUnsafeBytes() {
return bytes;
}

public ByteList toByteList() {
return new ByteList(bytes, start, length, encoding, true);
}

private void fromByteList(ByteList byteList) {
bytes = byteList.bytes();
start = 0;
length = byteList.length();
encoding = byteList.getEncoding();
}

public boolean equal(ParserByteListBuilder other) {
return toByteList().equals(other.toByteList());
}

public int charAt(int index) {
return toByteList().charAt(index);
}

public String toString() {
return toByteList().toString();
}

public ParserByteList toParserByteList() {
return new ParserByteList(Arrays.copyOfRange(bytes, start, length), 0, length, encoding);
return new ParserByteList(Arrays.copyOf(bytes, length), 0, length, encoding);
}

}
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
import org.jcodings.Encoding;
import org.jruby.truffle.core.regexp.RegexpOptions;
import org.jruby.truffle.core.string.ByteList;
import org.jruby.truffle.parser.ParserByteList;
import org.jruby.truffle.parser.ast.types.ILiteralNode;
import org.jruby.truffle.parser.ast.visitor.NodeVisitor;
import org.jruby.truffle.parser.TempSourceSection;
@@ -47,6 +48,10 @@ public class RegexpParseNode extends ParseNode implements ILiteralNode {
private final ByteList value;
private final RegexpOptions options;

public RegexpParseNode(TempSourceSection position, ParserByteList value, RegexpOptions options) {
this(position, new ByteList(value.getUnsafeBytes(), value.getStart(), value.getLength(), value.getEncoding(), false), options);
}

public RegexpParseNode(TempSourceSection position, ByteList value, RegexpOptions options) {
super(position, false);

Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
import org.jruby.truffle.core.rope.CodeRange;
import org.jruby.truffle.core.string.ByteList;
import org.jruby.truffle.core.string.StringSupport;
import org.jruby.truffle.parser.ParserByteList;
import org.jruby.truffle.parser.TempSourceSection;
import org.jruby.truffle.parser.ast.types.ILiteralNode;
import org.jruby.truffle.parser.ast.visitor.NodeVisitor;
@@ -49,10 +50,18 @@ public class StrParseNode extends ParseNode implements ILiteralNode, SideEffectF
private final CodeRange codeRange;
private boolean frozen;

public StrParseNode(TempSourceSection position, ParserByteList value) {
this(position, new ByteList(value.getUnsafeBytes(), value.getStart(), value.getLength(), value.getEncoding(), false));
}

public StrParseNode(TempSourceSection position, ByteList value) {
this(position, value, StringSupport.codeRangeScan(value.getEncoding(), value));
}

public StrParseNode(TempSourceSection position, ParserByteList value, CodeRange codeRange) {
this(position, new ByteList(value.getUnsafeBytes(), value.getStart(), value.getLength(), value.getEncoding(), false));
}

public StrParseNode(TempSourceSection position, ByteList value, CodeRange codeRange) {
super(position, false);

Original file line number Diff line number Diff line change
@@ -133,9 +133,11 @@ public int parseString(RubyLexer lexer) throws java.io.IOException {
}

if (str != null) {
str.append(lbuf.makeShared(p, pend - p).toBuilder());
str.append(lbuf.makeShared(p, pend - p));
} else {
str = new ParserByteListBuilder(lbuf.makeShared(p, pend - p).toBuilder());
final ParserByteListBuilder builder = new ParserByteListBuilder();
builder.append(lbuf.makeShared(p, pend - p));
str = builder;
}

if (pend < lexer.lex_pend) str.append('\n');
Original file line number Diff line number Diff line change
@@ -47,28 +47,26 @@ public class LexerSource {
private final Source source;
private final int lineStartOffset;

private final byte[] sourceBytes;
private Encoding encoding;
private ParserByteList sourceBytes;

private int byteOffset;

public LexerSource(Source source, int lineStartOffset, Encoding encoding) {
this.source = source;
this.lineStartOffset = lineStartOffset;
this.sourceBytes = source.getCode().getBytes(StandardCharsets.UTF_8);
this.encoding = encoding;
this.sourceBytes = new ParserByteList(source.getCode().getBytes(StandardCharsets.UTF_8), encoding);
}

public Source getSource() {
return source;
}

public Encoding getEncoding() {
return encoding;
return sourceBytes.getEncoding();
}

public void setEncoding(Encoding encoding) {
this.encoding = encoding;
sourceBytes = sourceBytes.withEncoding(encoding);
}

public int getOffset() {
@@ -80,29 +78,29 @@ public int getLineStartOffset() {
}

public ParserByteList gets() {
if (byteOffset >= sourceBytes.length) {
if (byteOffset >= sourceBytes.getLength()) {
return null;
}

int lineEnd = nextNewLine() + 1;

if (lineEnd == 0) {
lineEnd = sourceBytes.length;
lineEnd = sourceBytes.getLength();
}

final int start = byteOffset;
final int length = lineEnd - byteOffset;

byteOffset = lineEnd;

return new ParserByteList(sourceBytes, start, length, encoding);
return sourceBytes.makeShared(start, length);
}

private int nextNewLine() {
int n = byteOffset;

while (n < sourceBytes.length) {
if (sourceBytes[n] == '\n') {
while (n < sourceBytes.getLength()) {
if (sourceBytes.charAt(n) == '\n') {
return n;
}

Loading