HDFS-9221. HdfsServerConstants#ReplicaState#getState should avoid calling values() since it creates a temporary array. (Staffan Friberg via yliu)

This commit is contained in:
yliu 2015-10-12 14:28:15 +08:00
parent db93047881
commit 0ff1216100
2 changed files with 7 additions and 2 deletions

View File

@ -1509,6 +1509,9 @@ Release 2.8.0 - UNRELEASED
HDFS-9110. Use Files.walkFileTree in NNUpgradeUtil#doPreUpgrade for HDFS-9110. Use Files.walkFileTree in NNUpgradeUtil#doPreUpgrade for
better efficiency. (Charlie Helin via wang) better efficiency. (Charlie Helin via wang)
HDFS-9221. HdfsServerConstants#ReplicaState#getState should avoid calling
values() since it creates a temporary array. (Staffan Friberg via yliu)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than

View File

@ -299,6 +299,8 @@ enum ReplicaState {
/** Temporary replica: created for replication and relocation only. */ /** Temporary replica: created for replication and relocation only. */
TEMPORARY(4); TEMPORARY(4);
private static final ReplicaState[] cachedValues = ReplicaState.values();
private final int value; private final int value;
ReplicaState(int v) { ReplicaState(int v) {
@ -310,12 +312,12 @@ public int getValue() {
} }
public static ReplicaState getState(int v) { public static ReplicaState getState(int v) {
return ReplicaState.values()[v]; return cachedValues[v];
} }
/** Read from in */ /** Read from in */
public static ReplicaState read(DataInput in) throws IOException { public static ReplicaState read(DataInput in) throws IOException {
return values()[in.readByte()]; return cachedValues[in.readByte()];
} }
/** Write to out */ /** Write to out */