Esempio n. 1
0
 bool TryGetInner(Entry[] l0l1Cache, Type arg0, Type arg1, out CallsiteFunc <object, object, object> result)
 {
     for (var i = 0; i < l0l1Cache.Length; i++)
     {
         if (i >= count)
         {
             break;
         }
         var entry = l0l1Cache[i];
         if (entry.Signature.Match(arg0, arg1))
         {
             result = entry.Function;
             if (i > 0)
             {
                 // CacheSwap(0, i);
                 var temp = l0l1Cache[i];
                 l0l1Cache[i] = l0l1Cache[0];
                 l0l1Cache[0] = temp;
             }
             return(true);
         }
     }
     result = default;
     return(false);
 }
Esempio n. 2
0
        public object Invoke(object o)
        {
            if (cache.TryGet(o, out var result))
            {
                return(result(o));
            }

            CallsiteFunc <object, object> f = null;

            var oType = o == null ? typeof(Object) : o.GetType();
            var field = oType.GetField(MemberName);

            if (field != null)
            {
                f = DelegateHelpers.GetZeroArityDelegate(field);
            }
            var property = oType.GetProperty(MemberName);

            if (property != null)
            {
                f = DelegateHelpers.GetZeroArityDelegate(property);
            }
            var method = oType.GetMethod(MemberName, Type.EmptyTypes);

            if (method != null)
            {
                f = DelegateHelpers.GetZeroArityDelegate(method);
            }
            if (f != null)
            {
                cache.CacheMethod(o, f);
                return(f(o));
            }
            throw new ArgumentException($"Could not invoke zero arity member `{MemberName}` on target {(o == null ? "null" : o.ToString())}.");
        }
Esempio n. 3
0
        public object Invoke(object o, object value)
        {
            if (cache.TryGet(o, value, out var result))
            {
                return(result(o, value));
            }

            CallsiteFunc <object, object, object> f = null;

            var oType = o == null ? typeof(Object) : o.GetType();
            var field = oType.GetField(MemberName);

            if (field != null)
            {
                f = DelegateHelpers.GetSetMemberDelegate(field);
            }
            var property = oType.GetProperty(MemberName);

            if (property != null)
            {
                f = DelegateHelpers.GetSetMemberDelegate(property);
            }
            if (f != null)
            {
                cache.CacheMethod(o, value, f);
                return(f(o, value));
            }
            throw new ArgumentException($"Could not set member `{MemberName}` on target {o.ToString()}, no such member exists.");
        }
Esempio n. 4
0
        public void CacheMethod(object arg0, object arg1, CallsiteFunc <object, object, object> func)
        {
            var c = count < cacheSize ? count++ : count - 1;

            l0l1Cache[c] = new Entry {
                Signature = new Signature(arg0, arg1), Function = func
            };
            // CacheSwap(0, c);
            var temp = l0l1Cache[c];

            l0l1Cache[c] = l0l1Cache[0];
            l0l1Cache[0] = temp;
        }
Esempio n. 5
0
 public bool TryGet(object arg0, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, object arg11, object arg12, object arg13, object arg14, object arg15, object arg16, object arg17, out CallsiteFunc <object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object> result)
 {
     return(TryGetInner(l0l1Cache, arg0 == null ? typeof(object) : arg0.GetType(), arg1 == null ? typeof(object) : arg1.GetType(), arg2 == null ? typeof(object) : arg2.GetType(), arg3 == null ? typeof(object) : arg3.GetType(), arg4 == null ? typeof(object) : arg4.GetType(), arg5 == null ? typeof(object) : arg5.GetType(), arg6 == null ? typeof(object) : arg6.GetType(), arg7 == null ? typeof(object) : arg7.GetType(), arg8 == null ? typeof(object) : arg8.GetType(), arg9 == null ? typeof(object) : arg9.GetType(), arg10 == null ? typeof(object) : arg10.GetType(), arg11 == null ? typeof(object) : arg11.GetType(), arg12 == null ? typeof(object) : arg12.GetType(), arg13 == null ? typeof(object) : arg13.GetType(), arg14 == null ? typeof(object) : arg14.GetType(), arg15 == null ? typeof(object) : arg15.GetType(), arg16 == null ? typeof(object) : arg16.GetType(), arg17 == null ? typeof(object) : arg17.GetType(), out result));
 }
Esempio n. 6
0
        public void CacheMethod(object arg0, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, object arg11, object arg12, object arg13, object arg14, object arg15, object arg16, object arg17, CallsiteFunc <object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object> func)
        {
            var c = count < cacheSize ? count++ : count - 1;

            l0l1Cache[c] = new Entry {
                Signature = new Signature(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17), Function = func
            };
            // CacheSwap(0, c);
            var temp = l0l1Cache[c];

            l0l1Cache[c] = l0l1Cache[0];
            l0l1Cache[0] = temp;
        }
Esempio n. 7
0
 public bool TryGet(object arg0, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, out CallsiteFunc <object, object, object, object, object, object, object, object> result)
 {
     return(TryGetInner(l0l1Cache, arg0 == null ? typeof(object) : arg0.GetType(), arg1 == null ? typeof(object) : arg1.GetType(), arg2 == null ? typeof(object) : arg2.GetType(), arg3 == null ? typeof(object) : arg3.GetType(), arg4 == null ? typeof(object) : arg4.GetType(), arg5 == null ? typeof(object) : arg5.GetType(), arg6 == null ? typeof(object) : arg6.GetType(), out result));
 }
Esempio n. 8
0
 public bool TryGet(object arg0, object arg1, out CallsiteFunc <object, object, object> result)
 {
     return(TryGetInner(l0l1Cache, arg0 == null ? typeof(object) : arg0.GetType(), arg1 == null ? typeof(object) : arg1.GetType(), out result));
 }