Replaced lists with arrays in State to make the state class read-only
authorPanagiotis Kanavos <pkanavos@gmail.com>
Fri, 24 Feb 2012 11:26:12 +0000 (13:26 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Fri, 24 Feb 2012 11:26:12 +0000 (13:26 +0200)
trunk/Pithos.Core/Agents/SnapshotDifferencer.cs

index 3402d5f..5849624 100644 (file)
@@ -64,12 +64,12 @@ namespace Pithos.Core.Agents
             /// <summary>\r
             /// The previous snapshot listing\r
             /// </summary>\r
-            public readonly IEnumerable<ObjectInfo> Previous;\r
+            public readonly ObjectInfo[] Previous;\r
 \r
             /// <summary>\r
             /// The current snapshot listing\r
             /// </summary>\r
-            public readonly IEnumerable<ObjectInfo> Current;\r
+            public readonly ObjectInfo[] Current;\r
 \r
             /// <summary>\r
             /// Common objects, lazily evalueated. \r
@@ -77,10 +77,10 @@ namespace Pithos.Core.Agents
             /// </summary>\r
             public readonly Lazy<IEnumerable<ObjectInfo>> Common;\r
 \r
-            public State(IEnumerable<ObjectInfo> previous, IEnumerable<ObjectInfo> current)\r
+            public State(ObjectInfo[] previous, ObjectInfo[] current)\r
             {\r
-                Previous = previous ?? new List<ObjectInfo>();\r
-                Current = current ?? new List<ObjectInfo>();\r
+                Previous = previous ?? new ObjectInfo[0];\r
+                Current = current ?? new ObjectInfo[0];\r
 \r
                 Common=new Lazy<IEnumerable<ObjectInfo>>(() =>\r
                     Current.Join(Previous,\r
@@ -107,19 +107,9 @@ namespace Pithos.Core.Agents
         /// Default constructor. Initializes the Current and Previous listings to empty lists\r
         /// </summary>\r
         public SnapshotDifferencer()\r
-            :this(new List<ObjectInfo>(),new List<ObjectInfo>())\r
         {\r
-        }\r
-\r
-        /// <summary>\r
-        /// Creates a new differencer using the specified previous and current list. Null lists\r
-        /// are replaced with empty lists\r
-        /// </summary>\r
-        /// <param name="previous"></param>\r
-        /// <param name="current"></param>\r
-        public SnapshotDifferencer(IEnumerable<ObjectInfo> previous,IEnumerable<ObjectInfo> current  )\r
-        {\r
-            _state=new State(previous,current);\r
+            var empty = new ObjectInfo[0];            \r
+            _state = new State(empty, empty);\r
         }\r
 \r
         /// <summary>\r
@@ -129,7 +119,7 @@ namespace Pithos.Core.Agents
         /// <returns></returns>\r
         public SnapshotDifferencer Post(IEnumerable<ObjectInfo> list)\r
         {\r
-            List<ObjectInfo> newCurrent=null;\r
+            ObjectInfo[] newCurrent=null;\r
             if (list != null)\r
             {\r
                 //The state field holds the old state\r
@@ -139,7 +129,7 @@ namespace Pithos.Core.Agents
                 newCurrent = list.Replace(\r
                     info => info is NoModificationInfo,\r
                     noMod => oldState.Current.Where(noMod.CorrespondsTo))\r
-                    .ToList();\r
+                    .ToArray();\r
             }\r
             //Set the new state\r
             _state = new State(_state.Current, newCurrent);\r