Let's test and set _marshallers in the same place, and add a comment explaining

our no synchronization at the cost of possibly doing some trivial extra work.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6633 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2011-04-26 23:10:10 +00:00
parent 90e395c7bf
commit 10df7639b2
@@ -78,7 +78,9 @@ public abstract class FieldMarshaller
public static FieldMarshaller getFieldMarshaller (Field field)
{
if (_marshallers == null) {
createMarshallers();
// multiple threads may attempt to create the stock marshallers, but they'll just do
// extra work and _marshallers will only ever contain a fully populated table
_marshallers = createMarshallers();
}
// if necessary (we're running in a sandbox), look for custom field accessors
@@ -247,12 +249,10 @@ public abstract class FieldMarshaller
}
/**
* Creates instances of all known field marshaller types and populates the {@link
* #_marshallers} table with them. This is called the first time a marshaller is requested.
* Creates and returns a mapping for all known field marshaller types.
*/
protected static void createMarshallers ()
protected static Map<Class<?>, FieldMarshaller> createMarshallers ()
{
// create our table
Map<Class<?>, FieldMarshaller> marshallers = Maps.newHashMap();
// create a generic marshaller for streamable instances
@@ -404,7 +404,7 @@ public abstract class FieldMarshaller
}
};
_marshallers = marshallers;
return marshallers;
}
/** Contains a mapping from field type to field marshaller instance for that type. */