private bool CheckMatch(bool hasObject, CallbackArguments args, OverloadCacheItem overloadCacheItem)
        {
            if (overloadCacheItem.HasObject && !hasObject)
            {
                return(false);
            }

            if (args.Count != overloadCacheItem.ArgsDataType.Count)
            {
                return(false);
            }

            for (int i = 0; i < args.Count; i++)
            {
                if (args[i].Type != overloadCacheItem.ArgsDataType[i])
                {
                    return(false);
                }

                if (args[i].Type == DataType.UserData)
                {
                    if (args[i].UserData.Descriptor.Type != overloadCacheItem.ArgsUserDataType[i])
                    {
                        return(false);
                    }
                }
            }

            overloadCacheItem.HitIndexAtLastHit = ++m_CacheHits;
            return(true);
        }
コード例 #2
0
        private void Cache(bool hasObject, CallbackArguments args, IOverloadableMemberDescriptor bestOverload)
        {
            int lowestHits          = int.MaxValue;
            OverloadCacheItem found = null;

            for (int i = 0; i < m_Cache.Length; i++)
            {
                if (m_Cache[i] == null)
                {
                    found = new OverloadCacheItem
                    {
                        ArgsDataType = new List <DataType>(), ArgsUserDataType = new List <Type>()
                    };
                    m_Cache[i] = found;
                    break;
                }

                if (m_Cache[i].HitIndexAtLastHit < lowestHits)
                {
                    lowestHits = m_Cache[i].HitIndexAtLastHit;
                    found      = m_Cache[i];
                }
            }

            if (found == null)
            {
                // overflow..
                m_Cache = new OverloadCacheItem[CACHE_SIZE];
                found   = new OverloadCacheItem
                {
                    ArgsDataType = new List <DataType>(), ArgsUserDataType = new List <Type>()
                };
                m_Cache[0]  = found;
                m_CacheHits = 0;
            }

            found.Method            = bestOverload;
            found.HitIndexAtLastHit = ++m_CacheHits;
            found.ArgsDataType.Clear();
            found.HasObject = hasObject;

            for (int i = 0; i < args.Count; i++)
            {
                found.ArgsDataType.Add(args[i].Type);

                if (args[i].Type == DataType.UserData)
                {
                    found.ArgsUserDataType.Add(args[i].UserData.Descriptor.Type);
                }
                else
                {
                    found.ArgsUserDataType.Add(null);
                }
            }
        }