We only need to introspect and sort our fields array once per class, not
every time we create a distributed object. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2810 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
//
|
||||
// $Id: DObject.java,v 1.67 2003/09/23 17:16:46 mdb Exp $
|
||||
// $Id: DObject.java,v 1.68 2003/09/24 20:33:06 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.samskivert.util.ListUtil;
|
||||
import com.samskivert.util.StringUtil;
|
||||
@@ -104,9 +106,12 @@ public class DObject implements Streamable
|
||||
{
|
||||
public DObject ()
|
||||
{
|
||||
// introspect our fields into a sorted array
|
||||
_fields = getClass().getFields();
|
||||
Arrays.sort(_fields, FIELD_COMP);
|
||||
_fields = (Field[])_ftable.get(getClass());
|
||||
if (_fields == null) {
|
||||
_fields = getClass().getFields();
|
||||
Arrays.sort(_fields, FIELD_COMP);
|
||||
_ftable.put(getClass(), _fields);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -922,6 +927,10 @@ public class DObject implements Streamable
|
||||
* is removed. */
|
||||
protected transient boolean _deathWish = false;
|
||||
|
||||
/** Maintains a mapping of sorted field arrays for each distributed
|
||||
* object class. */
|
||||
protected static HashMap _ftable = new HashMap();
|
||||
|
||||
/** Used to sort and search {@link #_fields}. */
|
||||
protected static final Comparator FIELD_COMP = new Comparator() {
|
||||
public int compare (Object o1, Object o2) {
|
||||
|
||||
Reference in New Issue
Block a user