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:
@@ -24,6 +24,8 @@ package com.threerings.io;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.samskivert.util.HashIntMap;
|
import com.samskivert.util.HashIntMap;
|
||||||
@@ -82,7 +84,9 @@ public class ObjectInputStream extends DataInputStream
|
|||||||
|
|
||||||
// create our classmap if necessary
|
// create our classmap if necessary
|
||||||
if (_classmap == null) {
|
if (_classmap == null) {
|
||||||
_classmap = new HashIntMap<ClassMapping>();
|
_classmap = new ArrayList<ClassMapping>();
|
||||||
|
// insert a zeroth element
|
||||||
|
_classmap.add(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -129,7 +133,7 @@ public class ObjectInputStream extends DataInputStream
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmap = new ClassMapping(code, sclass, streamer);
|
cmap = new ClassMapping(code, sclass, streamer);
|
||||||
_classmap.put(code, cmap);
|
_classmap.add(code, cmap);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
cmap = _classmap.get(code);
|
cmap = _classmap.get(code);
|
||||||
@@ -141,7 +145,7 @@ public class ObjectInputStream extends DataInputStream
|
|||||||
"[code=" + code + ", ois=" + this + "].");
|
"[code=" + code + ", ois=" + this + "].");
|
||||||
Thread.dumpStack();
|
Thread.dumpStack();
|
||||||
log.warning("ObjectInputStream mappings " +
|
log.warning("ObjectInputStream mappings " +
|
||||||
StringUtil.toString(_classmap.entrySet()) +
|
StringUtil.toString(_classmap) +
|
||||||
".");
|
".");
|
||||||
String errmsg = "Read object code for which we " +
|
String errmsg = "Read object code for which we " +
|
||||||
"have no registered class metadata [code=" + code + "]";
|
"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}
|
/** Used to map classes to numeric codes and the {@link Streamer}
|
||||||
* instance used to write them. */
|
* instance used to write them. */
|
||||||
protected HashIntMap<ClassMapping> _classmap;
|
protected ArrayList<ClassMapping> _classmap;
|
||||||
|
|
||||||
/** The object currently being read from the stream. */
|
/** The object currently being read from the stream. */
|
||||||
protected Object _current;
|
protected Object _current;
|
||||||
|
|||||||
Reference in New Issue
Block a user