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

Commits on Dec 25, 2016

  1. Copy the full SHA
    963b629 View commit details
  2. Copy the full SHA
    582ae8c View commit details
Original file line number Diff line number Diff line change
@@ -314,21 +314,22 @@ public ByteList append(int b) {
*
* @param moreBytes to be added.
*/
public void append(byte[] moreBytes) {
public ByteList append(byte[] moreBytes) {
assert moreBytes != null : "moreBytes is null";

grow(moreBytes.length);
System.arraycopy(moreBytes, 0, bytes, begin + realSize, moreBytes.length);
realSize += moreBytes.length;
return this;
}

/**
* Append moreBytes onto the end of the current ByteList.
*
* @param moreBytes to be added.
*/
public void append(ByteList moreBytes) {
append(moreBytes.bytes, moreBytes.begin, moreBytes.realSize);
public ByteList append(ByteList moreBytes) {
return append(moreBytes.bytes, moreBytes.begin, moreBytes.realSize);
}

/**
@@ -339,8 +340,8 @@ public void append(ByteList moreBytes) {
* @param index new index past current begin value
* @param len is the number of bytes to append from source ByteList
*/
public void append(ByteList moreBytes, int index, int len) {
append(moreBytes.bytes, moreBytes.begin + index, len);
public ByteList append(ByteList moreBytes, int index, int len) {
return append(moreBytes.bytes, moreBytes.begin + index, len);
}

/**
@@ -351,7 +352,7 @@ public void append(ByteList moreBytes, int index, int len) {
* @param start is the new begin value
* @param len is the number of bytes to append from source byte array
*/
public void append(byte[] moreBytes, int start, int len) {
public ByteList append(byte[] moreBytes, int start, int len) {
assert moreBytes != null : "moreBytes is null";
// FIXME: Problems on CI box tripping on this. Re-enable later during 1.6 development.
//assert start >= 0 && (start == 0 || start < moreBytes.length) : "Invalid start";
@@ -360,6 +361,8 @@ public void append(byte[] moreBytes, int start, int len) {
grow(len);
System.arraycopy(moreBytes, start, bytes, begin + realSize, len);
realSize += len;

return this;
}

/**
85 changes: 36 additions & 49 deletions truffle/src/main/java/org/jruby/truffle/parser/ParserByteList.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.parser;

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

public class ParserByteList {

private final ByteList byteList;
private byte[] bytes;
private int start;
private int length;
private Encoding encoding;

public ParserByteList(ByteList byteList) {
this.byteList = byteList;
}

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

public ParserByteList() {
this(new ByteList());
fromByteList(byteList);
}

public ParserByteList(byte[] bytes, int start, int length, Encoding encoding, boolean copy) {
@@ -31,84 +35,67 @@ public ParserByteList(byte[] bytes) {
this(new ByteList(bytes));
}

public ParserByteList(ParserByteList other) {
this(new ByteList(other.byteList));
}

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

public int getStart() {
return byteList.getBegin();
return start;
}

public void setStart(int start) {
byteList.setBegin(start);
this.start = start;
}

public int getLength() {
return byteList.length();
return length;
}

public void setLength(int length) {
byteList.setRealSize(length);
this.length = length;
}

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

public void setEncoding(Encoding encoding) {
byteList.setEncoding(encoding);
}

public void append(int b) {
byteList.append(b);
}

public void append(byte[] bytes) {
byteList.append(bytes);
}

public void append(ParserByteList other, int start, int length) {
byteList.append(other.byteList, start, length);
}

public ParserByteList makeShared(int start, int length) {
return new ParserByteList(byteList.makeShared(start, length));
this.encoding = encoding;
}

public byte[] getUnsafeBytes() {
return byteList.getUnsafeBytes();
public ParserByteList makeShared(int sharedStart, int sharedLength) {
return new ParserByteList(bytes, start + sharedStart, sharedLength, encoding);
}

public int caseInsensitiveCmp(ParserByteList other) {
return byteList.caseInsensitiveCmp(other.byteList);
return toByteList().caseInsensitiveCmp(other.toByteList());
}

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

public boolean equal(ParserByteList other) {
return byteList.equals(other.byteList);
private void fromByteList(ByteList byteList) {
bytes = byteList.bytes();
start = 0;
length = byteList.length();
encoding = byteList.getEncoding();
}

public void ensure(int length) {
byteList.ensure(length);
public boolean equal(ParserByteList other) {
return toByteList().equals(other.toByteList());
}

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

public void append(ParserByteList other) {
byteList.append(other.byteList);
public String toString() {
return toByteList().toString();
}

public String toString() {
return byteList.toString();
public ParserByteListBuilder toBuilder() {
return new ParserByteListBuilder(toByteList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.parser;

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

import java.util.Arrays;

public class ParserByteListBuilder {

private byte[] bytes;
private int start;
private int length;
private 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;
}

public int getLength() {
return length;
}

public void setLength(int length) {
this.length = length;
}

public Encoding getEncoding() {
return encoding;
}

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

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

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

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

public void append(ParserByteListBuilder other) {
fromByteList(toByteList().append(other.toByteList()));
}

public void ensure(int length) {
bytes = Arrays.copyOf(bytes, Math.max(bytes.length, length));
}

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(toByteList());
}
}
Loading