Skip to content

Commit 8e3793f

Browse files
timeckljacomet
authored andcommitted
avoid garbage with enum values()
git-svn-id: https://svn.terracotta.org/repo/tc/tc-messaging/branches/private/voltron@26022 7fc7bbf3-cf45-46d4-be06-341739edd864
1 parent 62bbbf7 commit 8e3793f

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

src/main/java/com/tc/object/locks/ClientServerExchangeLockContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.io.IOException;
1515

1616
public class ClientServerExchangeLockContext implements TCSerializable<ClientServerExchangeLockContext> {
17+
private static final State[] STATE_VALUES = State.values();
18+
1719
private LockID lockID;
1820
private NodeID nodeID;
1921
private ThreadID threadID;
@@ -88,7 +90,7 @@ public ClientServerExchangeLockContext deserializeFrom(TCByteBufferInput input)
8890
ns.deserializeFrom(input);
8991
nodeID = ns.getNodeID();
9092
threadID = new ThreadID(input.readLong());
91-
state = State.values()[input.readInt()];
93+
state = STATE_VALUES[input.readInt()];
9294
if (state.getType() == Type.WAITER || state.getType() == Type.TRY_PENDING) {
9395
this.timeout = input.readLong();
9496
} else {

src/main/java/com/tc/object/locks/LockIDSerializer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.io.IOException;
1212

1313
public class LockIDSerializer implements TCSerializable<LockIDSerializer> {
14+
private static final LockIDType[] LOCK_ID_TYPE_VALUES = LockIDType.values();
15+
1416
private LockID lockID;
1517

1618
public LockIDSerializer() {
@@ -35,7 +37,7 @@ public LockIDSerializer deserializeFrom(TCByteBufferInput serialInput) throws IO
3537

3638
private LockID getImpl(byte type) {
3739
try {
38-
switch (LockIDType.values()[type]) {
40+
switch (LOCK_ID_TYPE_VALUES[type]) {
3941
case LONG:
4042
return new LongLockID();
4143
case STRING:

src/main/java/com/tc/object/msg/LockRequestMessage.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
*/
3232
public class LockRequestMessage extends DSOMessageBase implements MultiThreadedEventContext {
3333

34+
private static final RequestType[] REQUEST_TYPE_VALUES = RequestType.values();
35+
private static final ServerLockLevel[] SERVER_LOCK_LEVEL_VALUES = ServerLockLevel.values();
36+
3437
private final static byte LOCK_ID = 1;
3538
private final static byte LOCK_LEVEL = 2;
3639
private final static byte THREAD_ID = 3;
@@ -144,7 +147,7 @@ protected boolean hydrateValue(byte name) throws IOException {
144147
return true;
145148
case LOCK_LEVEL:
146149
try {
147-
lockLevel = ServerLockLevel.values()[getByteValue()];
150+
lockLevel = SERVER_LOCK_LEVEL_VALUES[getByteValue()];
148151
} catch (ArrayIndexOutOfBoundsException e) {
149152
return false;
150153
}
@@ -154,7 +157,7 @@ protected boolean hydrateValue(byte name) throws IOException {
154157
return true;
155158
case REQUEST_TYPE:
156159
try {
157-
requestType = RequestType.values()[getByteValue()];
160+
requestType = REQUEST_TYPE_VALUES[getByteValue()];
158161
} catch (ArrayIndexOutOfBoundsException e) {
159162
return false;
160163
}

src/main/java/com/tc/object/msg/LockResponseMessage.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
public class LockResponseMessage extends DSOMessageBase implements MultiThreadedEventContext {
2424

25+
private static final ServerLockLevel[] SERVER_LOCK_LEVEL_VALUES = ServerLockLevel.values();
26+
private static final ResponseType[] RESPONSE_TYPE_VALUES = ResponseType.values();
27+
2528
private static final byte TYPE = 1;
2629
private static final byte THREAD_ID = 2;
2730
private static final byte LOCK_ID = 3;
@@ -97,7 +100,7 @@ protected boolean hydrateValue(byte name) throws IOException {
97100
switch (name) {
98101
case TYPE:
99102
try {
100-
responseType = ResponseType.values()[getByteValue()];
103+
responseType = RESPONSE_TYPE_VALUES[getByteValue()];
101104
} catch (ArrayIndexOutOfBoundsException e) {
102105
return false;
103106
}
@@ -112,7 +115,7 @@ protected boolean hydrateValue(byte name) throws IOException {
112115
return true;
113116
case LOCK_LEVEL:
114117
try {
115-
lockLevel = ServerLockLevel.values()[getByteValue()];
118+
lockLevel = SERVER_LOCK_LEVEL_VALUES[getByteValue()];
116119
} catch (ArrayIndexOutOfBoundsException e) {
117120
return false;
118121
}

src/main/java/com/tc/object/msg/ServerEventSerializableContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
class ServerEventSerializableContext implements TCSerializable<ServerEventSerializableContext> {
2121

22+
private static final ServerEventType[] SERVER_EVENT_TYPE_VALUES = ServerEventType.values();
23+
2224
private static final DNAEncoding serializer = new SerializerDNAEncodingImpl();
2325

2426
private ServerEvent event;
@@ -54,7 +56,7 @@ public void serializeTo(final TCByteBufferOutput out) {
5456
public ServerEventSerializableContext deserializeFrom(TCByteBufferInput in) throws IOException {
5557
try {
5658
int index = (Integer) serializer.decode(in);
57-
final ServerEventType type = ServerEventType.values()[index];
59+
final ServerEventType type = SERVER_EVENT_TYPE_VALUES[index];
5860
final String destination = (String) serializer.decode(in);
5961
final Object key = serializer.decode(in);
6062
final byte[] value = (byte[]) serializer.decode(in);

0 commit comments

Comments
 (0)