From af7f98205a6ff0e4a32c04d8f161badc3d6ac055 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 21 Jun 2016 17:19:14 -0400 Subject: [PATCH] Inline StreamInput#readGenericValue --- .../common/io/stream/StreamInput.java | 91 ++++++++++++------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index ec56103e7a0..30b5cd7f2cf 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -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 */