2008-06-30 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Mon, 30 Jun 2008 11:38:02 +0000 (11:38 -0000)
committerMarek Safar <marek.safar@gmail.com>
Mon, 30 Jun 2008 11:38:02 +0000 (11:38 -0000)
* ResourceReader.cs: Cache resources enumerator in ResourceReader.

svn path=/trunk/mcs/; revision=106880

mcs/class/corlib/System.Resources/ChangeLog
mcs/class/corlib/System.Resources/ResourceReader.cs

index c0cd6038c98a592a698b483f2f6f06a863e3a6a6..1f55f330abafff8ad8014c20dde7ca36970735c9 100644 (file)
@@ -1,3 +1,7 @@
+2008-06-30  Marek Safar  <marek.safar@gmail.com>
+
+       * ResourceReader.cs: Cache resources enumerator in ResourceReader.
+
 2008-06-30  Marek Safar  <marek.safar@gmail.com>
 
        * ResourceReader.cs: Sealed ResourceEnumerator.
index d9b4f9e82572bc523b3b37674c3d900169c9afe2..070a44e00443f87910ff2fb1c55167dcfc670d62 100644 (file)
@@ -111,6 +111,8 @@ namespace System.Resources
                int dataSectionOffset;
                long nameSectionOffset;
                int resource_ver;
+               ResourceCacheItem[] cache;
+               object cache_lock = new object ();
                
                // Constructors
                [SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
@@ -557,11 +559,12 @@ namespace System.Resources
                                        reader.Close();
                                }
                        }
-
+                       
                        reader=null;
                        hashes=null;
                        infos=null;
                        typeNames=null;
+                       cache = null;
                }
                
                internal sealed class ResourceEnumerator : IDictionaryEnumerator
@@ -569,7 +572,6 @@ namespace System.Resources
                        private ResourceReader reader;
                        private int index = -1;
                        private bool finished;
-                       private ResourceCacheItem[] cache;
                        
                        internal ResourceEnumerator(ResourceReader readerToEnumerate)
                        {
@@ -582,18 +584,14 @@ namespace System.Resources
                                get { return index; }
                        }
 
-                       public DictionaryEntry Entry
-                       {
+                       public DictionaryEntry Entry {
                                get {
                                        if (reader.reader == null)
                                                throw new InvalidOperationException("ResourceReader is closed.");
                                        if (index < 0)
                                                throw new InvalidOperationException("Enumeration has not started. Call MoveNext.");
 
-                                       DictionaryEntry entry = new DictionaryEntry();
-                                       entry.Key = Key;
-                                       entry.Value = Value;
-                                       return entry; 
+                                       return new DictionaryEntry(Key, Value);
                                }
                        }
                        
@@ -605,7 +603,7 @@ namespace System.Resources
                                        if (index < 0)
                                                throw new InvalidOperationException("Enumeration has not started. Call MoveNext.");
 
-                                       return cache [index].ResourceName;
+                                       return reader.cache [index].ResourceName;
                                }
                        }
                        
@@ -616,7 +614,7 @@ namespace System.Resources
                                                throw new InvalidOperationException("ResourceReader is closed.");
                                        if (index < 0)
                                                throw new InvalidOperationException("Enumeration has not started. Call MoveNext.");
-                                       return cache [index].ResourceValue;
+                                       return reader.cache [index].ResourceValue;
                                }
                        }
                        
@@ -668,12 +666,17 @@ namespace System.Resources
 
                        void FillCache ()
                        {
-                               if (reader.reader == null)
+                               if (reader.cache != null)
                                        return;
+                               
+                               lock (reader.cache_lock) {
+                                       if (reader.cache != null)
+                                               return;
                                        
-                               ResourceCacheItem[] resources = new ResourceCacheItem [reader.resourceCount];                           
-                               reader.LoadResourceValues (resources);
-                               cache = resources;
+                                       ResourceCacheItem[] resources = new ResourceCacheItem [reader.resourceCount];                           
+                                       reader.LoadResourceValues (resources);
+                                       reader.cache = resources;
+                               }
                        }
                } // internal class ResourceEnumerator
        }  // public sealed class ResourceReader