Third time's a charm: apparently values() is problematic, so
let's try using a normal HashMap. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5104 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
package com.threerings.presents.net;
|
package com.threerings.presents.net;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.samskivert.util.HashIntMap;
|
import com.samskivert.util.HashIntMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,27 +141,23 @@ public class Transport
|
|||||||
// of instances and use Transport objects as keys (as in examples of the flyweight
|
// of instances and use Transport objects as keys (as in examples of the flyweight
|
||||||
// pattern). however, doing it this way avoids the need to create a new object on lookup
|
// pattern). however, doing it this way avoids the need to create a new object on lookup
|
||||||
if (_unordered == null) {
|
if (_unordered == null) {
|
||||||
int length = Type.values().length;
|
_unordered = new HashMap<Type, Transport>();
|
||||||
_unordered = new Transport[length];
|
_ordered = new HashMap<Type, HashIntMap<Transport>>();
|
||||||
@SuppressWarnings("unchecked") HashIntMap<Transport>[] ordered =
|
|
||||||
(HashIntMap<Transport>[])new HashIntMap[length];
|
|
||||||
_ordered = ordered;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for unordered transport, we map on the type alone
|
// for unordered transport, we map on the type alone
|
||||||
int idx = type.ordinal();
|
|
||||||
if (!type.isOrdered()) {
|
if (!type.isOrdered()) {
|
||||||
Transport instance = _unordered[idx];
|
Transport instance = _unordered.get(type);
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
_unordered[idx] = instance = new Transport(type);
|
_unordered.put(type, instance = new Transport(type));
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for ordered transport, we map on the type and channel
|
// for ordered transport, we map on the type and channel
|
||||||
HashIntMap<Transport> instances = _ordered[idx];
|
HashIntMap<Transport> instances = _ordered.get(type);
|
||||||
if (instances == null) {
|
if (instances == null) {
|
||||||
_ordered[idx] = instances = new HashIntMap<Transport>();
|
_ordered.put(type, instances = new HashIntMap<Transport>());
|
||||||
}
|
}
|
||||||
Transport instance = instances.get(channel);
|
Transport instance = instances.get(channel);
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
@@ -252,8 +250,8 @@ public class Transport
|
|||||||
|
|
||||||
/** Unordered instances mapped by type (would use {@link java.util.EnumMap}, but it doesn't
|
/** Unordered instances mapped by type (would use {@link java.util.EnumMap}, but it doesn't
|
||||||
* work with Retroweaver). */
|
* work with Retroweaver). */
|
||||||
protected static Transport[] _unordered;
|
protected static HashMap<Type, Transport> _unordered;
|
||||||
|
|
||||||
/** Ordered instances mapped by type and channel. */
|
/** Ordered instances mapped by type and channel. */
|
||||||
protected static HashIntMap<Transport>[] _ordered;
|
protected static HashMap<Type, HashIntMap<Transport>> _ordered;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user