Commits

Anonymous committed 0242233

second attempt for Settler

Comments (0)

Files changed (3)

Usually/Resolve.cs

     }
     public class Settler<T>
     {
-        public IResolverItem Add(string name, Meta<T> meta)
+        private class GenericItemList
+        {
+            private IMetaInfo<T> info = null;
+            private List<object[]> items = new List<object[]>();
+            private Dictionary<string, int> indexByName = null;
+            private int[] indexByNumber = null;
+            private void BuildValueNames(T obj)
+            {
+                if (this.indexByName == null)
+                {
+                    var byName = new Dictionary<string, int>();
+                    var byNumber = new List<int>();
+                    this.info.ForEachInsertValue(obj, (k, v) =>
+                    {
+                        var i = byName.ContainsKey(k) ? byName[k] : byName.Count;
+                        byNumber.Add(i);
+                        byName[k] = i;
+                    });
+                    this.indexByName = byName;
+                    this.indexByNumber = byNumber.ToArray();
+                }
+            }
+            public GenericItemList(IMetaInfo<T> info)
+            {
+                this.info = info;
+            }
+            private static bool FAST = true;
+            public object[] Add(T obj)
+            {
+                this.BuildValueNames(obj);
+                var item = new object[this.indexByName.Count];
+                int i = 0;
+                if (FAST)
+                {
+                    this.info.ForEachInsertValue(obj, (k, v) => item[this.indexByNumber[i++]] = v);
+                }
+                else
+                {
+                    this.info.ForEachInsertValue(obj, (k, v) => item[this.indexByName[k]] = v);
+                }
+                this.items.Add(item);
+                return item;
+            }
+            public void Clear()
+            {
+                this.items.Clear();
+            }
+            public int Count { get { return this.items.Count; } }
+            public void ForEach(Action<object[]> action)
+            {
+                this.items.ForEach(action);
+            }
+        }
+        public class SettlerItem
+        {
+            public SettlerItem Add(string name, Meta<T> meta)
+            {
+                return null;
+            }
+        }
+        public SettlerItem Add(string name, Meta<T> meta)
         {
             return null;
         }

UsuallyTests/Properties/Settings.Designer.cs

+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.1
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace UsuallyTests.Properties {
+    
+    
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+        
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+        
+        public static Settings Default {
+            get {
+                return defaultInstance;
+            }
+        }
+    }
+}

UsuallyTests/Properties/Settings.settings

+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+  <Profiles>
+    <Profile Name="(Default)" />
+  </Profiles>
+</SettingsFile>