diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index c1734cc..0c33a96 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -252,6 +252,14 @@ public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId, return this.code; } + private static Type[] codeArray = new Type[256]; + + static { + for (Type t : Type.values()) { + codeArray[t.code & 0xff] = t; + } + } + /** * Cannot rely on enum ordinals . They change if item is removed or moved. * Do our own codes. @@ -259,10 +267,9 @@ public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId, * @return Type associated with passed code. */ public static Type codeToType(final byte b) { - for (Type t : Type.values()) { - if (t.getCode() == b) { - return t; - } + Type t = codeArray[b & 0xff]; + if (t != null) { + return t; } throw new RuntimeException("Unknown code " + b); }