From 817c7014b4de71304fc1c0c614cfcef489a1e268 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 16 May 2008 21:25:22 +0000 Subject: [PATCH] Apparently EnumMap doesn't work with Retroweaver, so let's try using an array instead. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5103 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/net/Transport.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/java/com/threerings/presents/net/Transport.java b/src/java/com/threerings/presents/net/Transport.java index 94c3a02ba..d326ce976 100644 --- a/src/java/com/threerings/presents/net/Transport.java +++ b/src/java/com/threerings/presents/net/Transport.java @@ -21,8 +21,6 @@ package com.threerings.presents.net; -import java.util.EnumMap; - import com.samskivert.util.HashIntMap; /** @@ -141,23 +139,27 @@ public class Transport // 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 if (_unordered == null) { - _unordered = new EnumMap(Type.class); - _ordered = new EnumMap>(Type.class); + int length = Type.values().length; + _unordered = new Transport[length]; + @SuppressWarnings("unchecked") HashIntMap[] ordered = + (HashIntMap[])new HashIntMap[length]; + _ordered = ordered; } // for unordered transport, we map on the type alone + int idx = type.ordinal(); if (!type.isOrdered()) { - Transport instance = _unordered.get(type); + Transport instance = _unordered[idx]; if (instance == null) { - _unordered.put(type, instance = new Transport(type)); + _unordered[idx] = instance = new Transport(type); } return instance; } // for ordered transport, we map on the type and channel - HashIntMap instances = _ordered.get(type); + HashIntMap instances = _ordered[idx]; if (instances == null) { - _ordered.put(type, instances = new HashIntMap()); + _ordered[idx] = instances = new HashIntMap(); } Transport instance = instances.get(channel); if (instance == null) { @@ -248,9 +250,10 @@ public class Transport /** The transport channel. */ protected int _channel; - /** Unordered instances mapped by type. */ - protected static EnumMap _unordered; + /** Unordered instances mapped by type (would use {@link java.util.EnumMap}, but it doesn't + * work with Retroweaver). */ + protected static Transport[] _unordered; /** Ordered instances mapped by type and channel. */ - protected static EnumMap> _ordered; + protected static HashIntMap[] _ordered; }