コード例 #1
0
        private static void Walk(object o, int count)
        {
            Console.Write(o.ToString().PadRight(70, ' ') + count + "\t");

            var w = new FastHeapReferenceWalker();

            var set =
                //new ObjectSet<object>();
                new HashSet <object>(ReferenceEqualityComparer <object> .Instance);

            var sw = new Stopwatch();

            for (var i = 0; i < count; i++)
            {
                sw.Start();
                {
                    w.Walk(o, set.Add);
                }
                sw.Stop();

                set.Clear();
            }

            Console.WriteLine(sw.Elapsed);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: tamirdresher/reaqtor
        private static HashSet <object> AnalyzeFast(object obj)
        {
            var a = new FastHeapReferenceWalker();

            var set = new HashSet <object>(ReferenceEqualityComparer <object> .Instance);

            a.Walk(obj, set.Add);

            return(set);
        }
コード例 #3
0
        public void FastHeapReferenceWalker_Null()
        {
            var w = new FastHeapReferenceWalker();

            w.Walk(obj: null, _ =>
            {
                Assert.Fail();
                return(true);
            });
        }
コード例 #4
0
        public void FastHeapReferenceWalker_Vector_Value1()
        {
            var w = new FastHeapReferenceWalker();

            var xs = new[] { new KeyValuePair <int, int>(1, 2), new KeyValuePair <int, int>(2, 3), new KeyValuePair <int, int>(3, 4) };

            var set = new HashSet <object>(ReferenceEqualityComparer <object> .Instance);

            w.Walk(xs, set.Add);

            AssertSetEquals(set, new object[] { xs });
        }
コード例 #5
0
        public void FastHeapReferenceWalker_Vector_Ref2()
        {
            var w = new FastHeapReferenceWalker();

            var xs = new object[] { new object(), "bar", 42 };

            var set = new HashSet <object>(ReferenceEqualityComparer <object> .Instance);

            w.Walk(xs, set.Add);

            AssertSetEquals(set, new object[] { xs }.Concat(xs));
        }
コード例 #6
0
        public void FastHeapReferenceWalker_Object()
        {
            var w = new FastHeapReferenceWalker();

            var x = new object();

            var set = new HashSet <object>(ReferenceEqualityComparer <object> .Instance);

            w.Walk(x, set.Add);

            AssertSetEquals(set, x);
        }
コード例 #7
0
        public void FastHeapReferenceWalker_Vector_Value2()
        {
            var w = new FastHeapReferenceWalker();

            var xs = new[] { new KeyValuePair <int, object>(1, "bar"), new KeyValuePair <int, object>(2, new object()), new KeyValuePair <int, object>(3, 42) };

            var set = new HashSet <object>(ReferenceEqualityComparer <object> .Instance);

            w.Walk(xs, set.Add);

            AssertSetEquals(set, new object[] { xs }.Concat(xs.Select(x => x.Value)));
        }
コード例 #8
0
        public void FastHeapReferenceWalker_Multidimensional_Ref1()
        {
            var w = new FastHeapReferenceWalker();

            var xs = new object[2, 3] {
                { new object(), "bar", 42 }, { new object(), "qux", 43 }
            };

            var set = new HashSet <object>(ReferenceEqualityComparer <object> .Instance);

            w.Walk(xs, set.Add);

            AssertSetEquals(set, new object[] { xs }.Concat(xs.Cast <object>()));
        }
コード例 #9
0
        public void FastHeapReferenceWalker_Multidimensional_Value1()
        {
            var w = new FastHeapReferenceWalker();

            var xs = new KeyValuePair <int, object>[2, 3]
            {
                { new KeyValuePair <int, object>(1, "bar"), new KeyValuePair <int, object>(2, new object()), new KeyValuePair <int, object>(3, 42) },
                { new KeyValuePair <int, object>(4, "baz"), new KeyValuePair <int, object>(5, new object()), new KeyValuePair <int, object>(6, 43) },
            };

            var set = new HashSet <object>(ReferenceEqualityComparer <object> .Instance);

            w.Walk(xs, set.Add);

            AssertSetEquals(set, new object[] { xs }.Concat(xs.Cast <KeyValuePair <int, object> >().Select(kv => kv.Value)));
        }
コード例 #10
0
        public void FastHeapReferenceWalker_ArgumentChecking()
        {
            var w = new FastHeapReferenceWalker();

            Assert.ThrowsException <ArgumentNullException>(() => w.Walk(new object(), fence: null));
        }
コード例 #11
0
        public void FastHeapReferenceWalker_Deep()
        {
            var w = new FastHeapReferenceWalker();

            var bar =
                new Bar
            {
                X = 1,
                Y = "bar",
                Z = new Foo
                {
                    A = 2,
                    B = "qux",
                    C = new[]
                    {
                        new Qux
                        {
                            I = 3,
                            J = "foo",
                            K = new Baz
                            {
                                N = 4,
                                O = "baz",
                                P = new[]
                                {
                                    "abc",
                                    new object()
                                }
                            }
                        },
                        new Qux
                        {
                            I = 5,
                            J = "FOO",
                            K = new Baz
                            {
                                N = 6,
                                O = "BAZ",
                                P = new[]
                                {
                                    "xyz",
                                    new object()
                                }
                            }
                        }
                    }
                }
            };

            var set = new HashSet <object>(ReferenceEqualityComparer <object> .Instance);

            w.Walk(bar, set.Add);

            AssertSetEquals(set, new object[]
            {
                bar,
                bar.Y,
                bar.Z.B,
                bar.Z.C,
                bar.Z.C[0].J,
                bar.Z.C[0].K.O,
                bar.Z.C[0].K.P,
                bar.Z.C[0].K.P[0],
                bar.Z.C[0].K.P[1],
                bar.Z.C[1].J,
                bar.Z.C[1].K.O,
                bar.Z.C[1].K.P,
                bar.Z.C[1].K.P[0],
                bar.Z.C[1].K.P[1],
            });
        }