This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / corlib / System.Runtime.Serialization.Formatters.Binary / ObjectWriter.cs
index a9b9a8cfb49ab6de04093986e58333f956698a71..11f382914cc9a9b64365dce8e9c363e6210f92d9 100644 (file)
@@ -4,6 +4,29 @@
 //   Lluis Sanchez Gual (lluis@ideary.com)\r
 //\r
 // (C) 2003 Lluis Sanchez Gual\r
+
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 \r
 using System;\r
 using System.IO;\r
@@ -359,26 +382,28 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                        return;\r
                                }\r
                                \r
+                               Hashtable typesTable;\r
+                               bool isNew = false;\r
+                               lock (_cachedTypes) {\r
+                                       typesTable = (Hashtable) _cachedTypes [_context.State];\r
+                                       if (typesTable == null) {\r
+                                               typesTable = new Hashtable ();\r
+                                               _cachedTypes [_context.State] = typesTable;\r
+                                               isNew = true;\r
+                                       }\r
+                               }\r
+\r
                                metadata = null;\r
-                               lock (_cachedTypes)\r
-                               {\r
-                                       Hashtable typesTable = (Hashtable) _cachedTypes [_context.State];\r
-                                       if (typesTable != null)\r
-                                       {\r
+                               lock (typesTable) {\r
+                                       if (!isNew) {\r
                                                metadata = (TypeMetadata) typesTable [instanceType];\r
-                                               if (metadata == null) \r
-                                               {\r
-                                                       metadata = CreateMemberTypeMetadata (instanceType);\r
-                                                       typesTable [instanceType] = metadata;\r
-                                               }\r
                                        }\r
-                                       else\r
-                                       {\r
+\r
+                                       if (metadata == null) {\r
                                                metadata = CreateMemberTypeMetadata (instanceType);\r
-                                               typesTable = new Hashtable ();\r
-                                               typesTable [instanceType] = metadata;\r
-                                               _cachedTypes [_context.State] = typesTable;\r
                                        }\r
+\r
+                                       typesTable [instanceType] = metadata;\r
                                }\r
                        }\r
                }\r