public Key(RoDefinitionType genericTypeDefinition, RoType[] genericTypeArguments)
            {
                Debug.Assert(genericTypeDefinition != null);
                Debug.Assert(genericTypeArguments != null);

                GenericTypeDefinition = genericTypeDefinition;
                GenericTypeArguments  = genericTypeArguments;
            }
Esempio n. 2
0
        internal RoConstructedGenericType(RoDefinitionType genericTypeDefinition, RoType[] genericTypeArguments)
            : base()
        {
            Debug.Assert(genericTypeDefinition != null);
            Debug.Assert(genericTypeArguments != null);

            _genericTypeDefinition = genericTypeDefinition;
            _genericTypeArguments  = genericTypeArguments;
        }
Esempio n. 3
0
            public void Add(int hashCode, RoDefinitionType value)
            {
                int bucket      = ComputeBucket(hashCode, _buckets.Length);
                int newEntryIdx = _nextFreeEntry;

                _entries[newEntryIdx]._value    = value;
                _entries[newEntryIdx]._hashCode = hashCode;
                _entries[newEntryIdx]._next     = _buckets[bucket];

                _nextFreeEntry++;

                // The line that atomically adds the new key/value pair. If the thread is killed before this line executes but after
                // we've incremented _nextFreeEntry, this entry is harmlessly leaked until the next resize.
                Volatile.Write(ref _buckets[bucket], newEntryIdx);

                VerifyUnifierConsistency();
            }
Esempio n. 4
0
            public bool TryGetValue(ReadOnlySpan <byte> ns, ReadOnlySpan <byte> name, int hashCode, [NotNullWhen(true)] out RoDefinitionType?value)
            {
                // Lock acquistion NOT required.

                int bucket = ComputeBucket(hashCode, _buckets.Length);
                int i      = Volatile.Read(ref _buckets[bucket]);

                while (i != -1)
                {
                    if (hashCode == _entries[i]._hashCode)
                    {
                        RoDefinitionType actualValue = _entries[i]._value;
                        if (actualValue.IsTypeNameEqual(ns, name))
                        {
                            value = actualValue;
                            return(true);
                        }
                    }
                    i = _entries[i]._next;
                }

                value = default;
                return(false);
            }
Esempio n. 5
0
        internal RoDefinitionType GetTypeCore(ReadOnlySpan <byte> ns, ReadOnlySpan <byte> name, bool ignoreCase, out Exception e)
        {
            RoDefinitionType result = GetRoManifestModule().GetTypeCore(ns, name, ignoreCase, out e);

            if (IsSingleModule || result != null)
            {
                return(result);
            }

            foreach (RoModule module in ComputeRoModules(getResourceModules: false))
            {
                if (module == ManifestModule)
                {
                    continue;
                }

                result = module.GetTypeCore(ns, name, ignoreCase, out e);
                if (result != null)
                {
                    return(result);
                }
            }
            return(null);
        }
 //
 // Constructed Generic Types
 //
 internal RoConstructedGenericType GetUniqueConstructedGenericType(RoDefinitionType genericTypeDefinition, RoType[] genericTypeArguments)
 {
     return(_constructedGenericTypeDict.GetOrAdd(new RoConstructedGenericType.Key(genericTypeDefinition, genericTypeArguments), s_constructedGenericTypeFactory));
 }
Esempio n. 7
0
        public RoDefinitionType GetOrAdd(ReadOnlySpan <byte> ns, ReadOnlySpan <byte> name, int hashCode, RoDefinitionType type)
        {
            if (_container.TryGetValue(ns, name, hashCode, out RoDefinitionType? prior))
            {
                return(prior);
            }

            Monitor.Enter(_lock);
            try
            {
                if (_container.TryGetValue(ns, name, hashCode, out RoDefinitionType? winner))
                {
                    return(winner);
                }
                if (!_container.HasCapacity)
                {
                    _container.Resize(); // This overwrites the _container field.
                }
                _container.Add(hashCode, type);
                return(type);
            }
            finally
            {
                Monitor.Exit(_lock);
            }
        }
Esempio n. 8
0
 public bool TryGet(ReadOnlySpan <byte> ns, ReadOnlySpan <byte> name, int hashCode, out RoDefinitionType type)
 {
     return(_container.TryGetValue(ns, name, hashCode, out type));
 }
Esempio n. 9
0
 public static RoConstructedGenericType GetUniqueConstructedGenericType(this RoDefinitionType genericTypeDefinition, RoType[] genericTypeArguments) => genericTypeDefinition.GetRoModule().GetUniqueConstructedGenericType(genericTypeDefinition, genericTypeArguments);