Refactor to avoid linear lookup of streamers.
This was a bit of a rabbit hole and took longer than expected, and I had a stupid bug that took a while to find, but in the end there are way more lines of code removed than added, so I'll call it a win. Streamer lookup is now via a Dictionary. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5608 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -61,35 +61,16 @@ public class ArrayStreamer extends Streamer
|
||||
_elementType = Boolean;
|
||||
|
||||
} else {
|
||||
Log.getLog(this).warning("Other array types are " +
|
||||
"currently not handled yet [jname=" + jname + "].");
|
||||
Log.getLog(this).warning("Other array types are not yet handled", "jname", jname);
|
||||
throw new Error("Don't know how to stream '" + jname + "' instances.");
|
||||
}
|
||||
}
|
||||
|
||||
override public function isStreamerFor (obj :Object) :Boolean
|
||||
override public function getClass () :Class
|
||||
{
|
||||
if (obj is TypedArray) {
|
||||
// TypedArrays need the same element type
|
||||
return ((obj as TypedArray).getJavaType() === _jname);
|
||||
|
||||
} else {
|
||||
// any other array is streamed as Object[]
|
||||
return (obj is Array) && (_jname === "[Ljava.lang.Object;");
|
||||
}
|
||||
}
|
||||
|
||||
override public function isStreamerForClass (clazz :Class) :Boolean
|
||||
{
|
||||
if (clazz == TypedArray) {
|
||||
return false; // TODO: we're kinda fucked for finding a streamer
|
||||
// by class for TypedArrays here. The caller should be passing
|
||||
// the java name.
|
||||
|
||||
} else {
|
||||
return ClassUtil.isAssignableAs(Array, clazz) &&
|
||||
(_jname === "[Ljava.lang.Object;");
|
||||
}
|
||||
// this is a little weird, but basically, we don't want to be registered for Array
|
||||
// unless we're the basic Object array streamer.
|
||||
return (_jname == "[Ljava.lang.Object;") ? Array : null;
|
||||
}
|
||||
|
||||
override public function createObject (ins :ObjectInputStream) :Object
|
||||
|
||||
@@ -37,11 +37,6 @@ public class LongStreamer extends Streamer
|
||||
super(Long, "java.lang.Long");
|
||||
}
|
||||
|
||||
override public function createObject (ins :ObjectInputStream) :Object
|
||||
{
|
||||
return new Long();
|
||||
}
|
||||
|
||||
override public function writeObject (obj :Object, out :ObjectOutputStream) :void
|
||||
{
|
||||
var longy :Long = (obj as Long);
|
||||
|
||||
Reference in New Issue
Block a user