Skip to content

Commit 0894e07

Browse files
author
Adam Cozzette
committed
Integrated internal changes from Google
1 parent d52f2bb commit 0894e07

File tree

206 files changed

+7804
-4175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+7804
-4175
lines changed

cmake/libprotoc.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ set(libprotoc_files
7878
${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.cc
7979
${protobuf_source_dir}/src/google/protobuf/compiler/python/python_generator.cc
8080
${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator.cc
81-
${protobuf_source_dir}/src/google/protobuf/compiler/scc.cc
8281
${protobuf_source_dir}/src/google/protobuf/compiler/subprocess.cc
8382
${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.cc
8483
)

java/core/src/main/java/com/google/protobuf/BooleanArrayList.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ final class BooleanArrayList extends AbstractProtobufList<Boolean>
4646
implements BooleanList, RandomAccess, PrimitiveNonBoxingCollection {
4747

4848
private static final BooleanArrayList EMPTY_LIST = new BooleanArrayList();
49-
5049
static {
5150
EMPTY_LIST.makeImmutable();
5251
}
@@ -237,7 +236,7 @@ public boolean remove(Object o) {
237236
ensureIsMutable();
238237
for (int i = 0; i < size; i++) {
239238
if (o.equals(array[i])) {
240-
System.arraycopy(array, i + 1, array, i, size - i);
239+
System.arraycopy(array, i + 1, array, i, size - i - 1);
241240
size--;
242241
modCount++;
243242
return true;
@@ -252,7 +251,7 @@ public Boolean remove(int index) {
252251
ensureIndexInRange(index);
253252
boolean value = array[index];
254253
if (index < size - 1) {
255-
System.arraycopy(array, index + 1, array, index, size - index);
254+
System.arraycopy(array, index + 1, array, index, size - index - 1);
256255
}
257256
size--;
258257
modCount++;

java/core/src/main/java/com/google/protobuf/ByteString.java

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,24 @@ public byte[] copyFrom(byte[] bytes, int offset, int size) {
146146
*/
147147
public abstract byte byteAt(int index);
148148

149+
/**
150+
* Gets the byte at the given index, assumes bounds checking has already been performed.
151+
*
152+
* @param index index of byte
153+
* @return the value
154+
* @throws IndexOutOfBoundsException {@code index < 0 or index >= size}
155+
*/
156+
abstract byte internalByteAt(int index);
157+
149158
/**
150159
* Return a {@link ByteString.ByteIterator} over the bytes in the ByteString. To avoid
151160
* auto-boxing, you may get the iterator manually and call {@link ByteIterator#nextByte()}.
152161
*
153162
* @return the iterator
154163
*/
155164
@Override
156-
public final ByteIterator iterator() {
157-
return new ByteIterator() {
165+
public ByteIterator iterator() {
166+
return new AbstractByteIterator() {
158167
private int position = 0;
159168
private final int limit = size();
160169

@@ -163,24 +172,14 @@ public boolean hasNext() {
163172
return position < limit;
164173
}
165174

166-
@Override
167-
public Byte next() {
168-
// Boxing calls Byte.valueOf(byte), which does not instantiate.
169-
return nextByte();
170-
}
171-
172175
@Override
173176
public byte nextByte() {
174-
try {
175-
return byteAt(position++);
176-
} catch (IndexOutOfBoundsException e) {
177-
throw new NoSuchElementException(e.getMessage());
177+
int currentPos = position;
178+
if (currentPos >= limit) {
179+
throw new NoSuchElementException();
178180
}
179-
}
180-
181-
@Override
182-
public void remove() {
183-
throw new UnsupportedOperationException();
181+
position = currentPos + 1;
182+
return internalByteAt(currentPos);
184183
}
185184
};
186185
}
@@ -198,6 +197,19 @@ public interface ByteIterator extends Iterator<Byte> {
198197
byte nextByte();
199198
}
200199

200+
abstract static class AbstractByteIterator implements ByteIterator {
201+
@Override
202+
public final Byte next() {
203+
// Boxing calls Byte.valueOf(byte), which does not instantiate.
204+
return nextByte();
205+
}
206+
207+
@Override
208+
public final void remove() {
209+
throw new UnsupportedOperationException();
210+
}
211+
}
212+
201213
/**
202214
* Gets the number of bytes.
203215
*
@@ -1280,6 +1292,11 @@ public byte byteAt(int index) {
12801292
return bytes[index];
12811293
}
12821294

1295+
@Override
1296+
byte internalByteAt(int index) {
1297+
return bytes[index];
1298+
}
1299+
12831300
@Override
12841301
public int size() {
12851302
return bytes.length;
@@ -1521,6 +1538,11 @@ public byte byteAt(int index) {
15211538
return bytes[bytesOffset + index];
15221539
}
15231540

1541+
@Override
1542+
byte internalByteAt(int index) {
1543+
return bytes[bytesOffset + index];
1544+
}
1545+
15241546
@Override
15251547
public int size() {
15261548
return bytesLength;

java/core/src/main/java/com/google/protobuf/CodedInputStream.java

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,7 +2783,8 @@ private boolean tryRefillBuffer(int n) throws IOException {
27832783
sizeLimit - totalBytesRetired - bufferSize));
27842784
if (bytesRead == 0 || bytesRead < -1 || bytesRead > buffer.length) {
27852785
throw new IllegalStateException(
2786-
"InputStream#read(byte[]) returned invalid result: "
2786+
input.getClass()
2787+
+ "#read(byte[]) returned invalid result: "
27872788
+ bytesRead
27882789
+ "\nThe InputStream implementation is buggy.");
27892790
}
@@ -3005,20 +3006,46 @@ private void skipRawBytesSlowPath(final int size) throws IOException {
30053006
throw InvalidProtocolBufferException.truncatedMessage();
30063007
}
30073008

3008-
// Skipping more bytes than are in the buffer. First skip what we have.
3009-
int tempPos = bufferSize - pos;
3010-
pos = bufferSize;
3011-
3012-
// Keep refilling the buffer until we get to the point we wanted to skip to.
3013-
// This has the side effect of ensuring the limits are updated correctly.
3014-
refillBuffer(1);
3015-
while (size - tempPos > bufferSize) {
3016-
tempPos += bufferSize;
3009+
if (refillCallback != null) {
3010+
// Skipping more bytes than are in the buffer. First skip what we have.
3011+
int tempPos = bufferSize - pos;
30173012
pos = bufferSize;
3013+
3014+
// Keep refilling the buffer until we get to the point we wanted to skip to.
3015+
// This has the side effect of ensuring the limits are updated correctly.
30183016
refillBuffer(1);
3019-
}
3017+
while (size - tempPos > bufferSize) {
3018+
tempPos += bufferSize;
3019+
pos = bufferSize;
3020+
refillBuffer(1);
3021+
}
30203022

3021-
pos = size - tempPos;
3023+
pos = size - tempPos;
3024+
} else {
3025+
// Skipping more bytes than are in the buffer. First skip what we have.
3026+
totalBytesRetired += pos;
3027+
int totalSkipped = bufferSize - pos;
3028+
bufferSize = 0;
3029+
pos = 0;
3030+
3031+
try {
3032+
while (totalSkipped < size) {
3033+
int toSkip = size - totalSkipped;
3034+
long skipped = input.skip(toSkip);
3035+
if (skipped < 0 || skipped > toSkip) {
3036+
throw new IllegalStateException(
3037+
input.getClass()
3038+
+ "#skip returned invalid result: "
3039+
+ skipped
3040+
+ "\nThe InputStream implementation is buggy.");
3041+
}
3042+
totalSkipped += (int) skipped;
3043+
}
3044+
} finally {
3045+
totalBytesRetired += totalSkipped;
3046+
recomputeBufferSizeAfterLimit();
3047+
}
3048+
}
30223049
}
30233050
}
30243051

java/core/src/main/java/com/google/protobuf/DoubleArrayList.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ final class DoubleArrayList extends AbstractProtobufList<Double>
4646
implements DoubleList, RandomAccess, PrimitiveNonBoxingCollection {
4747

4848
private static final DoubleArrayList EMPTY_LIST = new DoubleArrayList();
49-
5049
static {
5150
EMPTY_LIST.makeImmutable();
5251
}
@@ -104,7 +103,7 @@ public boolean equals(Object o) {
104103

105104
final double[] arr = other.array;
106105
for (int i = 0; i < size; i++) {
107-
if (array[i] != arr[i]) {
106+
if (Double.doubleToLongBits(array[i]) != Double.doubleToLongBits(arr[i])) {
108107
return false;
109108
}
110109
}
@@ -237,7 +236,7 @@ public boolean remove(Object o) {
237236
ensureIsMutable();
238237
for (int i = 0; i < size; i++) {
239238
if (o.equals(array[i])) {
240-
System.arraycopy(array, i + 1, array, i, size - i);
239+
System.arraycopy(array, i + 1, array, i, size - i - 1);
241240
size--;
242241
modCount++;
243242
return true;
@@ -252,7 +251,7 @@ public Double remove(int index) {
252251
ensureIndexInRange(index);
253252
double value = array[index];
254253
if (index < size - 1) {
255-
System.arraycopy(array, index + 1, array, index, size - index);
254+
System.arraycopy(array, index + 1, array, index, size - index - 1);
256255
}
257256
size--;
258257
modCount++;

java/core/src/main/java/com/google/protobuf/FloatArrayList.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ final class FloatArrayList extends AbstractProtobufList<Float>
4646
implements FloatList, RandomAccess, PrimitiveNonBoxingCollection {
4747

4848
private static final FloatArrayList EMPTY_LIST = new FloatArrayList();
49-
5049
static {
5150
EMPTY_LIST.makeImmutable();
5251
}
@@ -104,7 +103,7 @@ public boolean equals(Object o) {
104103

105104
final float[] arr = other.array;
106105
for (int i = 0; i < size; i++) {
107-
if (array[i] != arr[i]) {
106+
if (Float.floatToIntBits(array[i]) != Float.floatToIntBits(arr[i])) {
108107
return false;
109108
}
110109
}
@@ -236,7 +235,7 @@ public boolean remove(Object o) {
236235
ensureIsMutable();
237236
for (int i = 0; i < size; i++) {
238237
if (o.equals(array[i])) {
239-
System.arraycopy(array, i + 1, array, i, size - i);
238+
System.arraycopy(array, i + 1, array, i, size - i - 1);
240239
size--;
241240
modCount++;
242241
return true;
@@ -251,7 +250,7 @@ public Float remove(int index) {
251250
ensureIndexInRange(index);
252251
float value = array[index];
253252
if (index < size - 1) {
254-
System.arraycopy(array, index + 1, array, index, size - index);
253+
System.arraycopy(array, index + 1, array, index, size - index - 1);
255254
}
256255
size--;
257256
modCount++;

0 commit comments

Comments
 (0)