diff --git a/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentType.java b/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentType.java index 56fff226114f8..242da6fd705dd 100644 --- a/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentType.java +++ b/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentType.java @@ -273,7 +273,7 @@ public static XContentType fromMediaType(String mediaTypeHeaderValue) throws Ill return null; } - private int index; + private final int index; XContentType(int index) { this.index = index; @@ -315,4 +315,10 @@ public ParsedMediaType toParsedMediaType() { public XContentType canonical() { return this; } + + private static final XContentType[] values = values(); + + public static XContentType ofOrdinal(int ordinal) { + return values[ordinal]; + } } diff --git a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java index eda28eb4e139e..b1ad328abda92 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -165,7 +165,8 @@ public IndexRequest(@Nullable ShardId shardId, StreamInput in) throws IOExceptio isRetry = in.readBoolean(); autoGeneratedTimestamp = in.readLong(); if (in.readBoolean()) { - contentType = in.readEnum(XContentType.class); + // faster than StreamInput::readEnum, do not replace we read a lot of these instances at times + contentType = XContentType.ofOrdinal(in.readByte()); } else { contentType = null; } diff --git a/server/src/main/java/org/elasticsearch/action/support/WriteRequest.java b/server/src/main/java/org/elasticsearch/action/support/WriteRequest.java index 0df640e3a50a1..64355a32c3a63 100644 --- a/server/src/main/java/org/elasticsearch/action/support/WriteRequest.java +++ b/server/src/main/java/org/elasticsearch/action/support/WriteRequest.java @@ -92,8 +92,10 @@ public static RefreshPolicy parse(String value) { throw new IllegalArgumentException("Unknown value for refresh: [" + value + "]."); } + private static final RefreshPolicy[] values = values(); + public static RefreshPolicy readFrom(StreamInput in) throws IOException { - return RefreshPolicy.values()[in.readByte()]; + return values[in.readByte()]; } @Override