From 10df7639b21fcd249de97b58ac8e69cca1869803 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 26 Apr 2011 23:10:10 +0000 Subject: [PATCH] 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 --- src/main/java/com/threerings/io/FieldMarshaller.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/threerings/io/FieldMarshaller.java b/src/main/java/com/threerings/io/FieldMarshaller.java index 8fc0785e4..0205bc3ac 100644 --- a/src/main/java/com/threerings/io/FieldMarshaller.java +++ b/src/main/java/com/threerings/io/FieldMarshaller.java @@ -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, FieldMarshaller> createMarshallers () { - // create our table Map, 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. */