Skip to content

Commit 53557e9

Browse files
committed
Removed ValueType.bitMask
1 parent 787533c commit 53557e9

File tree

3 files changed

+17
-82
lines changed

3 files changed

+17
-82
lines changed

msgpack-core/src/main/java/org/msgpack/core/MessageFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static MessageFormat valueOf(final byte b) {
9595
* @return
9696
*/
9797
@VisibleForTesting
98-
public static MessageFormat toMessageFormat(final byte b) {
98+
static MessageFormat toMessageFormat(final byte b) {
9999
if (Code.isPosFixInt(b)) {
100100
return POSFIXINT;
101101
}

msgpack-core/src/main/java/org/msgpack/value/ValueType.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,10 @@ public enum ValueType {
3434

3535
private final boolean numberType;
3636
private final boolean rawType;
37-
private final int bitMask;
3837

3938
private ValueType(boolean numberType, boolean rawType) {
4039
this.numberType = numberType;
4140
this.rawType = rawType;
42-
this.bitMask = 1 << this.ordinal();
43-
}
44-
45-
/**
46-
* Returns a bit mask representing this value type for quickly cheking
47-
* this value type
48-
* @return bit mask representing this value type
49-
*/
50-
public int getBitMask() {
51-
return bitMask;
52-
}
53-
54-
/**
55-
* Check whether the given bit mask represents this value type
56-
* @param bitMask
57-
* @return
58-
*/
59-
public boolean isTypeOf(int bitMask) {
60-
return (this.bitMask & bitMask) != 0;
6141
}
6242

6343
public boolean isNilType() {
@@ -104,10 +84,6 @@ public boolean isExtensionType() {
10484
return this == EXTENSION;
10585
}
10686

107-
public static ValueType valueOf(byte b) {
108-
return MessageFormat.valueOf(b).getValueType();
109-
}
110-
11187
public String toTypeName() {
11288
return this.name().substring(0, 1) + this.name().substring(1).toLowerCase();
11389
}

msgpack-core/src/test/scala/org/msgpack/value/ValueTypeTest.scala

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,97 +13,56 @@ class ValueTypeTest extends MessagePackSpec {
1313

1414
"ValueType" should {
1515

16-
"lookup ValueType from a byte value" taggedAs("code") in {
16+
"lookup ValueType from a byte value" taggedAs ("code") in {
1717

18-
def check(b:Byte, tpe:ValueType) {
19-
ValueType.valueOf(b) shouldBe tpe
18+
def check(b: Byte, tpe: ValueType) {
19+
MessageFormat.valueOf(b).getValueType shouldBe tpe
2020
}
2121

22-
for(i <- 0 until 0x7f)
22+
for (i <- 0 until 0x7f)
2323
check(i.toByte, ValueType.INTEGER)
2424

25-
for(i <- 0x80 until 0x8f)
25+
for (i <- 0x80 until 0x8f)
2626
check(i.toByte, ValueType.MAP)
2727

28-
for(i <- 0x90 until 0x9f)
28+
for (i <- 0x90 until 0x9f)
2929
check(i.toByte, ValueType.ARRAY)
3030

3131
check(NIL, ValueType.NIL)
3232

3333
try {
34-
ValueType.valueOf(NEVER_USED)
34+
MessageFormat.valueOf(NEVER_USED).getValueType
3535
fail("NEVER_USED type should not have ValueType")
3636
}
3737
catch {
38-
case e:MessageFormatException =>
39-
// OK
38+
case e: MessageFormatException =>
39+
// OK
4040
}
4141

4242
check(TRUE, ValueType.BOOLEAN)
4343
check(FALSE, ValueType.BOOLEAN)
4444

45-
for(t <- Seq(BIN8, BIN16, BIN32))
45+
for (t <- Seq(BIN8, BIN16, BIN32))
4646
check(t, ValueType.BINARY)
4747

48-
for(t <- Seq(FIXEXT1, FIXEXT2, FIXEXT4, FIXEXT8, FIXEXT16, EXT8, EXT16, EXT32))
48+
for (t <- Seq(FIXEXT1, FIXEXT2, FIXEXT4, FIXEXT8, FIXEXT16, EXT8, EXT16, EXT32))
4949
check(t, ValueType.EXTENSION)
5050

51-
for(t <- Seq(INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64))
51+
for (t <- Seq(INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64))
5252
check(t, ValueType.INTEGER)
5353

54-
for(t <- Seq(STR8, STR16, STR32))
54+
for (t <- Seq(STR8, STR16, STR32))
5555
check(t, ValueType.STRING)
5656

57-
for(t <- Seq(FLOAT32, FLOAT64))
57+
for (t <- Seq(FLOAT32, FLOAT64))
5858
check(t, ValueType.FLOAT)
5959

60-
for(t <- Seq(ARRAY16, ARRAY32))
60+
for (t <- Seq(ARRAY16, ARRAY32))
6161
check(t, ValueType.ARRAY)
6262

63-
for(i <- 0xe0 until 0xff)
63+
for (i <- 0xe0 until 0xff)
6464
check(i.toByte, ValueType.INTEGER)
6565

6666
}
67-
68-
"lookup table" in {
69-
70-
val N = 100000
71-
val idx = {
72-
val b = Array.newBuilder[Byte]
73-
for(i <- 0 until N) {
74-
val r = Iterator.continually(Random.nextInt(256)).find(_.toByte != Code.NEVER_USED).get
75-
b += r.toByte
76-
}
77-
b.result()
78-
}
79-
80-
time("lookup", repeat=100) {
81-
block("switch") {
82-
var i = 0
83-
while(i < N) {
84-
MessageFormat.toMessageFormat(idx(i)).getValueType()
85-
i += 1
86-
}
87-
}
88-
89-
block("table") {
90-
var i = 0
91-
while(i < N) {
92-
ValueType.valueOf(idx(i))
93-
i += 1
94-
}
95-
}
96-
97-
}
98-
99-
}
100-
101-
"support isTypeOf" in {
102-
for(v <- ValueType.values()) {
103-
v.isTypeOf(v.getBitMask) shouldBe true
104-
}
105-
}
106-
107-
10867
}
10968
}

0 commit comments

Comments
 (0)