private ArrayInitializerStyle ShouldEmitBlockInitializerForStackAlloc(TypeSymbol elementType, ImmutableArray <BoundExpression> inits)
        {
            if (!_module.SupportsPrivateImplClass)
            {
                return(ArrayInitializerStyle.Element);
            }

            elementType = elementType.EnumUnderlyingTypeOrSelf();

            if (elementType.SpecialType.IsBlittable())
            {
                int initCount  = 0;
                int constCount = 0;
                StackAllocInitializerCount(inits, ref initCount, ref constCount);

                if (initCount > 2)
                {
                    if (initCount == constCount)
                    {
                        return(ArrayInitializerStyle.Block);
                    }

                    int thresholdCnt = Math.Max(3, (initCount / 3));

                    if (constCount >= thresholdCnt)
                    {
                        return(ArrayInitializerStyle.Mixed);
                    }
                }
            }

            return(ArrayInitializerStyle.Element);
        }
Пример #2
0
        private ArrayInitializerStyle ShouldEmitBlockInitializer(
            TypeSymbol elementType,
            ImmutableArray <BoundExpression> inits
            )
        {
            if (!_module.SupportsPrivateImplClass)
            {
                return(ArrayInitializerStyle.Element);
            }

            if (elementType.IsEnumType())
            {
                if (!EnableEnumArrayBlockInitialization)
                {
                    return(ArrayInitializerStyle.Element);
                }
                elementType = elementType.EnumUnderlyingTypeOrSelf();
            }

            if (elementType.SpecialType.IsBlittable())
            {
                if (_module.GetInitArrayHelper() == null)
                {
                    return(ArrayInitializerStyle.Element);
                }

                int initCount  = 0;
                int constCount = 0;
                InitializerCountRecursive(inits, ref initCount, ref constCount);

                if (initCount > 2)
                {
                    if (initCount == constCount)
                    {
                        return(ArrayInitializerStyle.Block);
                    }

                    int thresholdCnt = Math.Max(3, (initCount / 3));

                    if (constCount >= thresholdCnt)
                    {
                        return(ArrayInitializerStyle.Mixed);
                    }
                }
            }

            return(ArrayInitializerStyle.Element);
        }
Пример #3
0
 public static IValueSetFactory?ForType(TypeSymbol type)
 {
     type = type.EnumUnderlyingTypeOrSelf();
     return(ForSpecialType(type.SpecialType, type.IsNativeIntegerType));
 }