Inline StreamInput#readGenericValue

This commit is contained in:
Jason Tedor 2016-06-21 17:19:14 -04:00
parent 9d1ef62431
commit af7f98205a
1 changed files with 60 additions and 31 deletions

View File

@ -439,45 +439,21 @@ public abstract class StreamInput extends InputStream {
case 5:
return readBoolean();
case 6:
int bytesSize = readVInt();
byte[] value = new byte[bytesSize];
readBytes(value, 0, bytesSize);
return value;
return fastReadByteArray();
case 7:
int size = readVInt();
List list = new ArrayList(size);
for (int i = 0; i < size; i++) {
list.add(readGenericValue());
}
return list;
return readArrayList();
case 8:
int size8 = readVInt();
Object[] list8 = new Object[size8];
for (int i = 0; i < size8; i++) {
list8[i] = readGenericValue();
}
return list8;
return readArray();
case 9:
int size9 = readVInt();
Map map9 = new LinkedHashMap(size9);
for (int i = 0; i < size9; i++) {
map9.put(readString(), readGenericValue());
}
return map9;
return readLinkedHashMap();
case 10:
int size10 = readVInt();
Map map10 = new HashMap(size10);
for (int i = 0; i < size10; i++) {
map10.put(readString(), readGenericValue());
}
return map10;
return readHashMap();
case 11:
return readByte();
case 12:
return new Date(readLong());
return readDate();
case 13:
final String timeZoneId = readString();
return new DateTime(readLong(), DateTimeZone.forID(timeZoneId));
return readDateTime();
case 14:
return readBytesReference();
case 15:
@ -501,6 +477,59 @@ public abstract class StreamInput extends InputStream {
}
}
private byte[] fastReadByteArray() throws IOException {
int bytesSize = readVInt();
byte[] value = new byte[bytesSize];
readBytes(value, 0, bytesSize);
return value;
}
@SuppressWarnings("unchecked")
private List readArrayList() throws IOException {
int size = readVInt();
List list = new ArrayList(size);
for (int i = 0; i < size; i++) {
list.add(readGenericValue());
}
return list;
}
private DateTime readDateTime() throws IOException {
final String timeZoneId = readString();
return new DateTime(readLong(), DateTimeZone.forID(timeZoneId));
}
private Object[] readArray() throws IOException {
int size8 = readVInt();
Object[] list8 = new Object[size8];
for (int i = 0; i < size8; i++) {
list8[i] = readGenericValue();
}
return list8;
}
private Map readLinkedHashMap() throws IOException {
int size9 = readVInt();
Map map9 = new LinkedHashMap(size9);
for (int i = 0; i < size9; i++) {
map9.put(readString(), readGenericValue());
}
return map9;
}
private Map readHashMap() throws IOException {
int size10 = readVInt();
Map map10 = new HashMap(size10);
for (int i = 0; i < size10; i++) {
map10.put(readString(), readGenericValue());
}
return map10;
}
private Date readDate() throws IOException {
return new Date(readLong());
}
/**
* Reads a {@link GeoPoint} from this stream input
*/