Repository: hadoop
Updated Branches:
  refs/heads/branch-2.7 e1798e8f2 -> 2c51bbda5


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


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/2c51bbda
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/2c51bbda
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/2c51bbda

Branch: refs/heads/branch-2.7
Commit: 2c51bbda510577506b3711c28b422b633ac59e5e
Parents: e1798e8
Author: Kihwal Lee <[email protected]>
Authored: Mon Nov 2 09:07:16 2015 -0600
Committer: Kihwal Lee <[email protected]>
Committed: Mon Nov 2 09:07:16 2015 -0600

----------------------------------------------------------------------
 hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt                    | 3 +++
 .../apache/hadoop/hdfs/server/common/HdfsServerConstants.java  | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c51bbda/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt 
b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index 8cf1bd9..314caa8 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -16,6 +16,9 @@ Release 2.7.2 - UNRELEASED
     HDFS-8099. Change "DFSInputStream has been closed already" message to
     debug log level (Charles Lamb via Colin P. McCabe)
 
+    HDFS-9221. HdfsServerConstants#ReplicaState#getState should avoid calling
+    values() since it creates a temporary array. (Staffan Friberg via yliu)
+
   OPTIMIZATIONS
 
     HDFS-8722. Optimize datanode writes for small writes and flushes (kihwal)

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c51bbda/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java
index 8af3af7..e5bcecf 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java
@@ -250,6 +250,8 @@ public final class HdfsServerConstants {
     /** Temporary replica: created for replication and relocation only. */
     TEMPORARY(4);
 
+    private static final ReplicaState[] cachedValues = ReplicaState.values();
+
     private final int value;
 
     private ReplicaState(int v) {
@@ -261,12 +263,12 @@ public final class HdfsServerConstants {
     }
 
     public static ReplicaState getState(int v) {
-      return ReplicaState.values()[v];
+      return cachedValues[v];
     }
 
     /** Read from in */
     public static ReplicaState read(DataInput in) throws IOException {
-      return values()[in.readByte()];
+      return cachedValues[in.readByte()];
     }
 
     /** Write to out */

Reply via email to