We don't need to hash, just use an ArrayList.

ObjectInputStream works in conjunction with a ObjectOutputStream on the
other end. The ObjectOutputStream will always assign class codes starting
at 1 and increasing sequentially from there, so we can look up a class
by index rather than hashing.
Uses less memory and is faster.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4365 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-09-08 18:02:08 +00:00
parent e973c00b50
commit b596aa724e
@@ -24,6 +24,8 @@ package com.threerings.io;
import java.io.InputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import com.samskivert.util.HashIntMap;
@@ -82,7 +84,9 @@ public class ObjectInputStream extends DataInputStream
// create our classmap if necessary
if (_classmap == null) {
_classmap = new HashIntMap<ClassMapping>();
_classmap = new ArrayList<ClassMapping>();
// insert a zeroth element
_classmap.add(null);
}
try {
@@ -129,7 +133,7 @@ public class ObjectInputStream extends DataInputStream
}
cmap = new ClassMapping(code, sclass, streamer);
_classmap.put(code, cmap);
_classmap.add(code, cmap);
} else {
cmap = _classmap.get(code);
@@ -141,7 +145,7 @@ public class ObjectInputStream extends DataInputStream
"[code=" + code + ", ois=" + this + "].");
Thread.dumpStack();
log.warning("ObjectInputStream mappings " +
StringUtil.toString(_classmap.entrySet()) +
StringUtil.toString(_classmap) +
".");
String errmsg = "Read object code for which we " +
"have no registered class metadata [code=" + code + "]";
@@ -224,7 +228,7 @@ public class ObjectInputStream extends DataInputStream
/** Used to map classes to numeric codes and the {@link Streamer}
* instance used to write them. */
protected HashIntMap<ClassMapping> _classmap;
protected ArrayList<ClassMapping> _classmap;
/** The object currently being read from the stream. */
protected Object _current;