Repository: hadoop
Updated Branches:
  refs/heads/trunk db9304788 -> 0ff121610


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


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

Branch: refs/heads/trunk
Commit: 0ff1216100d16cfa862854a89cd1be8969b0bd7e
Parents: db93047
Author: yliu <[email protected]>
Authored: Mon Oct 12 14:28:15 2015 +0800
Committer: yliu <[email protected]>
Committed: Mon Oct 12 14:28:15 2015 +0800

----------------------------------------------------------------------
 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/0ff12161/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 541dc99..4171433 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -1509,6 +1509,9 @@ Release 2.8.0 - UNRELEASED
     HDFS-9110. Use Files.walkFileTree in NNUpgradeUtil#doPreUpgrade for
     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
 
     HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than

http://git-wip-us.apache.org/repos/asf/hadoop/blob/0ff12161/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 6208a7d..13c9137 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
@@ -299,6 +299,8 @@ public interface HdfsServerConstants {
     /** Temporary replica: created for replication and relocation only. */
     TEMPORARY(4);
 
+    private static final ReplicaState[] cachedValues = ReplicaState.values();
+
     private final int value;
 
     ReplicaState(int v) {
@@ -310,12 +312,12 @@ public interface 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